# Handle errors

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

Source: https://docs.gastrogate.io/docs/guides/error-handling

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"] }
  ]
}
```

## Recommended handling

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](https://docs.gastrogate.io/docs/api.md) 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);
}
```
