Skip to main content

Error handling

GraphQL queries and mutations can generate errors that fall into two categories - developer errors and user errors. Developer errors occur when you try to customize applications that use our GraphQL APIs. They indicate that something went wrong during the request, which could be due to a server issue such as a server exception, dependency issues, or an issue in the developer's integration such as unauthorized access or an entity not found. Such errors can occur with both queries and mutations.

We’ve tried to cover some of these errors in this section.

Error type/descriptionExtension code
Input Format Errors - Example: An empty string is provided as an input for cartIdBAD_REQUEST
Graphql syntax errors - Example: Sub-fields of an object are not provided for a query/mutationGRAPHQL_VALIDATION_FAILED
Entity not found - Example: The client lacks valid authentication credentials but requests a field which at a minimum requires authenticationNOT_FOUND
Authentication or authorization issues - Example: The client lacks valid authentication credentials but requests a field which at a minimum requires authenticationUNAUTHORIZED
Client has insufficient authorization permissions to perform an action - Example: The bearer token provided in the authorization header doesn’t have necessary permissions to perform a actionFORBIDDEN
Query cost limit exceeded - Example: The client has exceeded the allowed limit for a single requestRESOURCE_LIMIT_EXCEEDED
Rate limit exceeded - The client has exceeded the allowed limit for multiple requests during a given period of timeRATE_LIMIT_EXCEEDED
Server errors*INTERNAL_SERVER_ERROR

For example:

Mutation:

mutation applyDiscountToCart($input: ApplyDiscountInput!) {
applyDiscountToCart(input: $input) {
cart {
id
items {
id
}
}
}
}

Input:

{
"input": {
"cartId": "",
"discountCode": "FOOBAR"
}
}

Output:

{
"errors": [
{
"message": "cartId cannot be empty",
"path": [
"applyDiscountToCart"
],
"extensions": {
"code": "BAD_REQUEST"
}
}
],
"data": {
"applyDiscountToCart": null
}
}

Other errors

In addition to some of the common errors mentioned above, you may also encounter other errors based on your inputs and due to validation issues related to business rules. For instance, if you try to apply an invalid discount code while placing an order, the mutation will return an error. We've covered some of these errors as well in the respective sections for mutations.

Was this page helpful?