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.
{
"data": { "restaurant": null },
"errors": [
{ "message": "Not authorized", "path": ["restaurant"] }
]
}Recommended handling
- Network / HTTP errors — retry with exponential backoff for
5xxand timeouts. errorsarray present — logmessageandpath. Treat the fields named inpathas missing.- Permission errors — check the required permission in the reference for the operation.
const body = await res.json();
if (body.errors?.length) {
for (const e of body.errors) console.error(e.path?.join("."), e.message);
}