Developers Dashboard

One error shape for every endpoint, the codes and statuses, and what to do about each.

Every error has one shape:

JSON
{
  "error": {
    "code": "invalid_request",
    "message": "The request body is invalid.",
    "details": { "issues": [{ "path": "name", "message": "Required" }] }
  }
}
  • code is stable and machine-readable. Branch on it, not on the message.
  • message is a sentence a person can act on. It is safe to show.
  • details is there when there is more to say: issues or fields (keyed by the path of the value) for validation errors, errors and warnings for an invalid page or SiteSpec, problems when a workflow can't be published, and scope for a missing scope.

Codes

CodeStatusMeansDo
bad_request400The request is malformed, for example not JSON.Fix the request.
confirmation_required400Deleting a site needs ?confirm=<siteId>.Add the confirmation.
unauthorized401No key, or the key isn't valid or was revoked.Check the Authorization header.
forbidden403The key or the account's role can't do this.Use an owner's or admin's key.
insufficient_scope403The key lacks the scope; details.scope names it.Make a key with that scope.
not_found404Not found, or not reachable with this key.Check the id and the key's sites.
conflict409It clashes with the current state: a taken hostname, a read-only synced collection, a request still in progress.Read the message; retry later for in-progress.
gone410Already deleted.Nothing to do.
precondition_failed412The page changed since you read it.Read it again, then change it. See ETags.
too_large413The file or body is too large.Send less.
unsupported_media_type415That file type isn't supported.See Media for the types.
invalid_request422The body is invalid; details says which values.Fix the values named.
invalid_spec422A page or SiteSpec has problems; details.errors lists them by path.Fix each path.
idempotency_mismatch422The Idempotency-Key was used before with a different body.Use a new key. See Idempotency.
rate_limited429Too many requests.Wait Retry-After seconds. See Rate limits.
internal_error500Something went wrong on our side.Retry with backoff.

Handle them

const res = await fetch(url, { headers });
if (!res.ok) {
  const { error } = await res.json();
  if (error.code === 'precondition_failed') {
    // Someone changed the page: read it again and reapply your change.
  } else if (error.code === 'rate_limited') {
    await new Promise((r) => setTimeout(r, Number(res.headers.get('Retry-After')) * 1000));
  } else {
    throw new Error(`${res.status} ${error.code}: ${error.message}`);
  }
}