Dev

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

SituationWhat to do
Schema/syntax errorA bug in your query — fix at build time. Validate queries with the Dev MCP server or cloudcart app validate before shipping
Missing/invalid storefront tokenCheck the X-Storefront-Access-Token header; re-run cloudcart nitrogen env pull if the token rotated
Expired customer JWTPrompt re-login, retry the request with the fresh token
Partial data with errorsRender what you got; log the errors — often one nullable field failed while the rest succeeded
Network / 5xxRetry with backoff; show cached data if you have it

Golden rules

  1. Check errors even on HTTP 200. A successful transport does not mean a successful query.
  2. Don't show raw GraphQL errors to shoppers. Map them to friendly UI states; log the details.
  3. Fail soft on catalog pages. A missing recommendation block shouldn't take down the product page — wrap optional sections separately.

On this page