# Errors and retries (https://docs.fuser.studio/docs/api/errors)

A failed request returns a JSON body with a message written to be acted on:

```json
{
  "code": "BAD_REQUEST",
  "message": "The diff was rejected. Fix every error and resend: ..."
}
```

A 409 also has a `reason`: `stale_revision`, `idempotency_key_reused` or
`canvas_not_editable`. A 400 for invalid input lists `issues`, each with a
`message` and the `path` of the field.

| Status | Meaning                                                                                                                 |
| ------ | ----------------------------------------------------------------------------------------------------------------------- |
| 400    | The request is wrong; the message says how.                                                                             |
| 401    | The API key is missing or invalid.                                                                                      |
| 403    | The key can't do this, or you can't use this workspace.                                                                 |
| 404    | The canvas, run or file doesn't exist, or isn't yours.                                                                  |
| 409    | The canvas changed since you read it, or a run was retried with the same `idempotencyKey` but a different `maxCredits`. |
| 429    | Over 300 requests a minute from one key. Wait the `Retry-After` header's seconds and try again.                         |
| 5xx    | Fuser had a problem. Retry with the same `idempotencyKey`.                                                              |

## Retrying safely [#retrying-safely]

`canvas_edit` and `run_start` take an `idempotencyKey`. Sending the same request
again with the same key returns the first result instead of doing it twice,
so retry with the same key after a timeout or dropped connection.

`canvas_edit` also takes `expectedRevision`: the edit is refused with 409 if
someone changed the canvas since you read it. Read it again and resend.