Error Handling
How Storefront API errors are shaped and how to handle them in a storefront.
GraphQL always answers 200 OK when the request reaches the API — errors travel in the response body's errors array, possibly alongside partial data.
Error shape
{
"errors": [
{
"message": "Cannot query field \"tittle\" on type \"Product\". Did you mean \"title\"?",
"locations": [{ "line": 3, "column": 5 }]
}
],
"data": null
}Handling strategy for storefronts
| Situation | What to do |
|---|---|
| Schema/syntax error | A bug in your query — fix at build time. Validate queries with the Dev MCP server or cloudcart app validate before shipping |
| Missing/invalid storefront token | Check the X-Storefront-Access-Token header; re-run cloudcart nitrogen env pull if the token rotated |
| Expired customer JWT | Prompt re-login, retry the request with the fresh token |
Partial data with errors | Render what you got; log the errors — often one nullable field failed while the rest succeeded |
| Network / 5xx | Retry with backoff; show cached data if you have it |
Golden rules
- Check
errorseven on HTTP 200. A successful transport does not mean a successful query. - Don't show raw GraphQL errors to shoppers. Map them to friendly UI states; log the details.
- Fail soft on catalog pages. A missing recommendation block shouldn't take down the product page — wrap optional sections separately.