# Errors

Source: https://watership.ca/api-docs/docs/reference/errors

Every problem type the API can respond with, with its status code, its cause, and whether a retry can help.

Errors are problem objects as defined in [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457), sent with the content type `application/problem+json`.

## The problem object [#the-problem-object]

```json
{
  "type": "https://watership.ca/api/problems/text-too-long",
  "title": "The text is too long",
  "status": 400,
  "detail": "\"text\" is 131,072 characters; the limit is 100,000. Split the text and check each part.",
  "instance": "req_3Kd9pX7vB2",
  "limit": 100000,
  "errors": [{ "pointer": "/text", "detail": "Longer than 100,000 characters." }]
}
```

| Field | Type | Always present | Description |
|---|---|---|---|
| `type` | string (URI) | yes | Identifies the kind of problem. Branch on this. |
| `title` | string | yes | A short summary, the same for every problem of one type. |
| `status` | integer | yes | The HTTP status code. |
| `detail` | string | yes | What went wrong with this request, and what to do. |
| `instance` | string | no | An id for this occurrence. Quote it when you report a problem. |
| `errors` | array | no | For `invalid-request` and `text-too-long`: one item per field, each with a `pointer` and a `detail`. |
| `limit` | integer | no | For `text-too-long` and `payload-too-large`: the limit the request exceeded. |

A `pointer` is a JSON Pointer ([RFC 6901](https://www.rfc-editor.org/rfc/rfc6901)) into the request body, such as `/min_level`. For a query parameter, it's the parameter name after `#/query/`, such as `#/query/limit`.

The type URIs are stable identifiers. They don't resolve to a page yet.

## Problem types [#problem-types]

All types start with `https://watership.ca/api/problems/`.

| Type | Status | Cause | Retry? | Mock example |
|---|---|---|---|---|
| `invalid-request` | 400 | Malformed JSON, a missing or unknown field, or a value outside the allowed set | No. Fix the request. | `invalidRequest` |
| `text-too-long` | 400 | `text` is over 100,000 characters | No. Split the text. | `textTooLong` |
| `unauthorized` | 401 | No `Authorization` header, or the key isn't valid | No. Fix the key. | `missingKey` |
| `not-found` | 404 | No rule, term, or voice has that id | No | `unknownRule` |
| `payload-too-large` | 413 | The request body is over 1 MiB (1,048,576 bytes) | No. Split the text. | `bodyTooLarge` |
| `unsupported-media-type` | 415 | The body isn't sent as `application/json` | No. Fix the header. | `notJson` |
| `rate-limited` | 429 | The key sent more than 120 requests this minute | Yes, after `Retry-After` seconds | `rateLimited` |
| `internal` | 500 | A fault on the server | Yes, with backoff | `internal` |
| `check-timeout` | 503 | The check took longer than 5 seconds and was stopped | Not with the same text. Split it. | `timeout` |

To get one of these from the mock server, send a `Prefer` header with the status code and the example name, such as `Prefer: code=400, example=textTooLong`.

## Endpoints and their errors [#endpoints-and-their-errors]

| Endpoint | Can return |
|---|---|
| `POST /v1/checks` | 400, 401, 413, 415, 429, 500, 503 |
| `GET /v1/rules`, `GET /v1/terms`, `GET /v1/voices` | 400, 401, 429, 500 |
| `GET /v1/rules/{rule_id}`, `GET /v1/terms/{term_id}`, `GET /v1/voices/{voice_id}` | 400, 401, 404, 429, 500 |

[Handle errors and rate limits](https://watership.ca/api-docs/docs/tasks/handle-errors-and-rate-limits) shows how to act on each type.
