Errors
HTTP statuses and stable codes for each error of the public API.
Every error comes as JSON with the status and a stable code. Compare by code, never by text: the API does not return sentences.
{ "statusCode": 404, "code": "NOT_FOUND" }Codes
| Status | code | When |
|---|---|---|
| 400 | BAD_USER_INPUT | Invalid parameter (perPage=500, page=abc, repeated parameter). |
| 400 | LOCALE_NOT_ENABLED | locale outside the site's languages. |
| 401 | UNAUTHENTICATED | Missing, invalid or revoked key. |
| 403 | SECRET_KEY_IN_BROWSER | Secret key with a browser Origin (and the site did not allow it). See Allowed domains. |
| 403 | ORIGIN_NOT_ALLOWED | Publishable key with no origin or from an origin outside the allowed domains. |
| 403 | KEY_KIND_NOT_ALLOWED | Publishable key on the per-site route (/sites/{siteId}/…). |
| 404 | NOT_FOUND | Slug does not exist, is not published or belongs to another site; a key of another site on the per-site route. |
| 429 | RATE_LIMITED | The key's rate limit. See Rate limit. |
Responses that are not errors
301: old slug of a published post. See Get a post.304: nothing changed since theETagyou sent. See Cache.
How to handle them
if (res.status === 404) return null; // the post does not exist (or went offline)
if (!res.ok) {
const { code } = await res.json();
throw new Error(`Postream ${res.status} ${code}`);
}