# Error codes

URL: https://docs.folkways.io/docs/realtime-api/errors

Every Realtime API error code, its HTTP status, whether it closes the connection, and what to do about it.

Every transport uses the same codes. A code that closes the connection arrives as a `Close` frame; the others as an
`OpError` for one request, and the connection stays open. Over HTTP, packet-level failures also set the status, and
the JSON endpoints answer `{ "code", "error", "message" }`. Codes are grouped by hundreds.

## Request [#request]

| Code | Name | HTTP | Closes | Retry | Means |
| ---: | --- | ---: | --- | --- | --- |
| 100 | `BadFrame` | 400 | yes | never | Not a valid packet: wrong identifier, failed verification, a text message |
| 101 | `InvalidArgument` | 400 | no | never | A field is missing or wrong |
| 102 | `UnsupportedVersion` | 400 | yes | never | The protocol version isn't supported |
| 103 | `UnsupportedFrame` | 400 | no | never | A frame not accepted here, e.g. `Subscribe` on `/v1/publish`. Ten close the connection |
| 104 | `UnsupportedFeature` | 400 | no | never | A feature this server doesn't offer |
| 105 | `FrameTooLarge` | 413 | yes | never | A packet over `max_frame_bytes` |
| 106 | `HelloRequired` | 400 | yes | never | Another frame came before `Hello` |

## Authentication and access [#authentication-and-access]

| Code | Name | HTTP | Closes | Retry | Means |
| ---: | --- | ---: | --- | --- | --- |
| 200 | `AuthRequired` | 401 | yes | with a token | No token, or no `Hello` within 5 s |
| 201 | `AuthInvalid` | 401 | yes | never | Bad signature, unknown key, wrong segment, bad claims; a revoked or expired publishable key |
| 202 | `AuthExpired` | 401 | yes | with a new token | The token has expired |
| 203 | `Forbidden` | 403 | no | never | No rule matches, or the token, rule or member entry doesn't allow it. The same answer for both, so topics can't be probed |
| 204 | `Suspended` | 403 | yes | never | The segment is off, the workspace's package isn't active, or the publishable key is paused |
| 205 | `ResumeRejected` | 409 | no | never | Reserved for session resume, which isn't offered |
| 206 | `Replaced` | 409 | yes | **don't reconnect automatically** | A newer connection of the same identity took this one's place |
| 207 | `AuthRevoked` | 401 | yes | **don't reconnect automatically** | Your backend kicked this identity or revoked this token |

## Limits [#limits]

| Code | Name | HTTP | Closes | Retry | Means |
| ---: | --- | ---: | --- | --- | --- |
| 300 | `RateLimited` | 429 | no* | after `retry_after_ms` | A rate limit: publishes, bytes, subscribes, topic creations, new connections, failed authentications |
| 301 | `QuotaExceeded` | 429 | no* | after `retry_after_ms` | A connection, topic, subscription, member or monthly limit |
| 302 | `PayloadTooLarge` | 413 | no | never | The payload is over the limit |
| 303 | `Backpressure` | 503 | yes | reconnect and resume | The connection couldn't keep up with deliveries |

\* `RateLimited` and `QuotaExceeded` close the connection only when they answer `Hello`. A publish refused for a
monthly allowance gets a `retry_after_ms` that ends at the next period: retrying sooner fails again unless you
upgrade or raise the cap. Subscriptions and deliveries are never cut for quotas.

## Topics [#topics]

| Code | Name | HTTP | Closes | Retry | Means |
| ---: | --- | ---: | --- | --- | --- |
| 400 | `InvalidTopic` | 400 | no | never | Not a valid topic name. A reserved `$` name other than a system topic gets `Forbidden` |
| 401 | `ClassMismatch` | 409 | no | never | The event type isn't allowed for this event name or topic |
| 402 | `InvalidCursor` | 400 | no | never | The cursor is ahead of the topic |
| 403 | `IdempotencyConflict` | 409 | no | never | The idempotency key was used with different content |
| 404 | `IdempotencyKeyRequired` | 400 | no | never | A stream publish without an idempotency key |

## Server [#server]

| Code | Name | HTTP | Closes | Retry | Means |
| ---: | --- | ---: | --- | --- | --- |
| 500 | `Internal` | 500 | no | with backoff | An unexpected server error |
| 501 | `Unavailable` | 503 | yes | with backoff | A dependency is unavailable |
| 502 | `Draining` | 503 | yes | reconnect after `retry_after_ms` | The server is restarting; you'll reach another |
| 503 | `Overloaded` | 503 | no | with backoff | The server is busy |
| 504 | `Timeout` | 504 | yes | reconnect | 90 seconds with nothing received |

## Handling errors [#handling-errors]

- **Retry with backoff and jitter** only where the table says so, and never sooner than `retry_after_ms`.
- **Never retry `Forbidden`, `InvalidArgument` or `PayloadTooLarge` unchanged.** Fix the request, the token or the
  rule.
- **After `Replaced` or `AuthRevoked`**, stop: show "signed in elsewhere" or sign the user out.
- **After `Draining` or `Backpressure`**, reconnect and resume from your saved cursors.

The JavaScript SDK adds its own local codes (1000–1006) for things that happen in the client, such as a full queue:
see [JavaScript errors](/docs/js-sdk/errors).
