---
title: "Error handling"
description: "Interpret App API status codes and typed JSON errors, and decide when to retry."
url: "https://www.thecompany.company/docs/api/errors"
---

# Error handling

> Interpret App API status codes and typed JSON errors, and decide when to retry.

Check the HTTP status first. When the API returns a typed JSON error, its top-level `_tag` identifies the error and the other fields give details. Branch on the status and `_tag`, not on human-readable text, and handle unrecognized or non-JSON responses.

## Example response [#example-response]

An invalid [access token](/docs/api/authentication) can return `401 Unauthorized` with:

```json
{
  "_tag": "AuthenticationError",
  "reason": "invalid_access_token"
}
```

## Common status codes [#common-status-codes]

| Status | What to do |
| --- | --- |
| `400` Bad Request | Check the path, query, or body against the operation’s schema. |
| `401` Unauthorized | Check that the Bearer token is present, valid, and unexpired. |
| `402` Payment Required | Check the organization’s subscription. |
| `403` Forbidden | Check the token’s scopes and the caller’s access to the organization and resource. |
| `404` Not Found | Check the ID and whether the caller can see the resource. |
| `409` Conflict | Check whether the resource is in a state that allows this operation. |
| `429` Too Many Requests | Wait before retrying. See [rate limits](/docs/api/rate-limits#handle-a-429) for the header and error body. |
| `500` Internal Server Error | Check the result before repeating a write. |
| `503` Service Unavailable | The operation may be temporarily unavailable. If the response includes `Retry-After`, wait at least that long. |

## Retry safely [#retry-safely]

- Correct a rejected request before repeating it. For a `429`, [back off](/docs/api/rate-limits) rather than immediately repeating it.
- If a write times out or returns a server error, don’t assume it failed. Check the session or read its events before resending a request that could create a duplicate.
- If an event stream fails after it opens, the HTTP status stays `200`. Handle the stream failure and [resume from your last saved event ID](/docs/api/streaming#resume-or-skip-history).

Not every response has a body. A successful [session message send](/docs/api/sessions/send-message) returns `204 No Content`; don’t parse it as JSON or treat it as completion of the session’s work.
