Errors
Every non-2xx answer is the original API’s error shape, with the original API’s codes and messages.
The envelope#
An error is always an object with one array, errors, holding one item with exactly two fields:
{
"errors": [
{
"code": 3,
"message": "The user id is invalid."
}
]
}That is the shape the original API used, and the codes and messages are its own too: an endpoint answers with the error the original endpoint gave for the same situation, word for word. Each endpoint’s reference page lists the errors it can return.
The code field#
code means something only together with the endpoint and the HTTP status: the users service’s 404 is code 3 because the original users service’s was, and another endpoint’s code 3 can mean something else entirely. Match on status, code and endpoint together, never on the code alone.
Code 0 is never an endpoint’s own error. It is the answer from the layer in front of the endpoints: authentication, a path that does not exist, the wrong HTTP method, a refusal, a server fault.
The HTTP status#
| Status | When | Body |
|---|---|---|
400 | The endpoint rejected a value, with its own error; or a parameter is outside what it accepts, such as a limit that is not 10, 25, 50 or 100. | The endpoint’s own error, or code 0 — "Something went wrong with the request, see response status code." |
401 | No key, or a key that does not work. See Authentication. | code 0 — "Authorization has been denied for this request." |
403 | Your key, or an anonymous caller, cannot use this service; or the endpoint refused the action itself. | code 0 for the key, the endpoint’s own error otherwise |
404 | The thing you asked for does not exist, or the path matches no endpoint. | The endpoint’s own error, or code 0 — "No HTTP resource was found that matches the request URI '…'." |
405 | The path exists, but not for this HTTP method. | code 0 — "The requested resource does not support http method 'GET'." |
429 | Over your rate budget. See Rate limits. | The endpoint’s own 429 if it had one, otherwise code 0 |
500 | Something failed on the server. | code 0 — "An error has occurred." |
503 | The API or this service is switched off, or the site is in maintenance. See below. | code 0 |
A path whose number is not a number, such as /v1/users/abc, matches no endpoint, so it is the 404 above — before your key is even checked.
The legacy service is different#
The legacy service reproduces the older API, which had its own convention for every error: the code is the HTTP status and the message is the status’s name.
{
"errors": [
{
"code": 404,
"message": "NotFound"
}
]
}| Status | Message |
|---|---|
400 | BadRequest |
401 | Unauthorized |
403 | Forbidden |
404 | NotFound |
405 | MethodNotAllowed |
429 | TooManyRequests |
500 | InternalServerError |
503 | ServiceUnavailable |
That includes refusals: a key that cannot use the legacy service gets {"code":403,"message":"Forbidden"} and nothing more. As in the original, asking for a user that does not exist is a 400, not a 404.
Why a 503 happens#
A 503 always means "come back later", never "this endpoint doesn’t exist". Three different switches answer this way:
- The API is off entirely. An administrator has not turned the API on, or has switched it off. Every endpoint answers 503 until it is back.
- One service is disabled. Only that service answers 503; the rest keep working.
- The site is in maintenance. The API goes down with the rest of the site by default, and answers in JSON rather than with the site’s maintenance page, so a JSON parser never chokes on markup. Some deployments keep the API up through maintenance. When they do not, expect:
{
"errors": [
{
"code": 0,
"message": "The site is in maintenance. The API is unavailable until it returns."
}
]
}A 503 is worth a short backoff-and-retry, not a permanent give-up. Unlike a 404, the endpoint you called is real and will answer again.