How-to guides

Handle errors

Detect and handle GraphQL errors, partial data and network failures.

GraphQL responses can contain both data and errors. Always check for errors, even when the HTTP status is 200.

json
{
  "data": { "restaurant": null },
  "errors": [
    { "message": "Not authorized", "path": ["restaurant"] }
  ]
}
  1. Network / HTTP errors — retry with exponential backoff for 5xx and timeouts.
  2. errors array present — log message and path. Treat the fields named in path as missing.
  3. Permission errors — check the required permission in the reference for the operation.
typescript
const body = await res.json();
if (body.errors?.length) {
  for (const e of body.errors) console.error(e.path?.join("."), e.message);
}