Postream

Loading the index…

Docs: Errors

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

StatuscodeWhen
400BAD_USER_INPUTInvalid parameter (perPage=500, page=abc, repeated parameter).
400LOCALE_NOT_ENABLEDlocale outside the site's languages.
401UNAUTHENTICATEDMissing, invalid or revoked key.
403SECRET_KEY_IN_BROWSERSecret key with a browser Origin (and the site did not allow it). See Allowed domains.
403ORIGIN_NOT_ALLOWEDPublishable key with no origin or from an origin outside the allowed domains.
403KEY_KIND_NOT_ALLOWEDPublishable key on the per-site route (/sites/{siteId}/…).
404NOT_FOUNDSlug does not exist, is not published or belongs to another site; a key of another site on the per-site route.
429RATE_LIMITEDThe 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 the ETag you 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}`);
}