Dev

Error Handling

Understand and handle errors returned by the CloudCart Admin API.

The Admin API follows the standard GraphQL error format. Errors are returned in the errors array alongside any partial data in the response body. The HTTP status code is 200 OK for most GraphQL errors -- you must inspect the response body to detect problems.

Error Response Format

Every error object contains these fields:

FieldTypeDescription
messageStringHuman-readable error description
path[String]The field path in the query where the error occurred
extensions.codeStringMachine-readable error code for programmatic handling
{
  "data": null,
  "errors": [
    {
      "message": "Human-readable description",
      "path": ["fieldName"],
      "extensions": {
        "code": "ERROR_CODE"
      }
    }
  ]
}

Error Codes

CodeHTTP StatusDescription
NOT_FOUND200The requested resource does not exist
UNAUTHORIZED401Missing or invalid authentication token
FORBIDDEN403Token lacks permission for this operation
VALIDATION_ERROR200Input data failed validation
RATE_LIMITED429Too many requests -- slow down
INTERNAL_ERROR500Unexpected server error

NOT_FOUND

Returned when you query or mutate a resource that does not exist.

Request

query {
  product(id: 99999) {
    id
    name
  }
}

Response

{
  "data": {
    "product": null
  },
  "errors": [
    {
      "message": "Product not found",
      "path": ["product"],
      "extensions": {
        "code": "NOT_FOUND"
      }
    }
  ]
}

How to Handle

Check if the resource field is null and inspect extensions.code. This commonly occurs when a resource has been deleted or the ID is wrong.

UNAUTHORIZED

Returned when the Authorization header is missing, malformed, or contains an expired/revoked token.

Request

POST /api/gql HTTP/1.1
Host: mystore.cloudcart.com
Content-Type: application/json

(No Authorization header)

Response (HTTP 401)

{
  "errors": [
    {
      "message": "Authentication required. Provide a valid Bearer token in the Authorization header.",
      "extensions": {
        "code": "UNAUTHORIZED"
      }
    }
  ]
}

How to Handle

Verify that your request includes Authorization: Bearer <token> and that the token has not been revoked. Generate a new token from Settings > API Keys in your store admin panel.

FORBIDDEN

Returned when the token is valid but does not have the required permissions.

Response (HTTP 403)

{
  "errors": [
    {
      "message": "Your token does not have permission to perform this action.",
      "path": ["orderUpdate"],
      "extensions": {
        "code": "FORBIDDEN"
      }
    }
  ]
}

How to Handle

Check the scopes assigned to your API token. Update the token's permissions in Settings > API Keys to include the required scope.

VALIDATION_ERROR

Returned when mutation input fails server-side validation. The response includes field-level details.

Request

mutation {
  createProduct(input: {
    name: ""
    price: -5
  }) {
    id
  }
}

Response

{
  "data": {
    "createProduct": null
  },
  "errors": [
    {
      "message": "Validation failed",
      "path": ["createProduct"],
      "extensions": {
        "code": "VALIDATION_ERROR",
        "validationErrors": [
          {
            "field": "name",
            "message": "Name can't be blank"
          },
          {
            "field": "price",
            "message": "Price must be greater than or equal to 0"
          }
        ]
      }
    }
  ]
}

How to Handle

Iterate over extensions.validationErrors and map each entry back to the relevant input field. Display the message to the user or fix the input programmatically.

const errors = response.errors?.[0]?.extensions?.validationErrors;
if (errors) {
  errors.forEach(({ field, message }) => {
    console.error(`${field}: ${message}`);
  });
}

RATE_LIMITED

Returned when you exceed the API rate limit (120 requests per minute per token).

Response (HTTP 429)

{
  "errors": [
    {
      "message": "Rate limit exceeded. Retry after 32 seconds.",
      "extensions": {
        "code": "RATE_LIMITED",
        "retryAfter": 32
      }
    }
  ]
}

Response Headers

HTTP/1.1 429 Too Many Requests
X-RateLimit-Limit: 120
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1710422400
Retry-After: 32

How to Handle

Wait for the number of seconds specified in extensions.retryAfter or the Retry-After header before retrying. Implement exponential backoff for repeated rate limit hits.

async function fetchWithRetry(query, variables, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    const response = await fetch(ENDPOINT, {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${TOKEN}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ query, variables }),
    });

    if (response.status === 429) {
      const retryAfter = parseInt(response.headers.get("Retry-After") || "5");
      await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
      continue;
    }

    return response.json();
  }

  throw new Error("Max retries exceeded");
}

INTERNAL_ERROR

Returned when an unexpected server error occurs. These are rare and typically transient.

Response (HTTP 500)

{
  "errors": [
    {
      "message": "An internal error occurred. Please try again later.",
      "extensions": {
        "code": "INTERNAL_ERROR",
        "requestId": "req_abc123def456"
      }
    }
  ]
}

How to Handle

Retry the request after a short delay. If the error persists, contact CloudCart support and include the requestId value from the response.

Partial Data with Errors

GraphQL can return partial data alongside errors. For example, if one field in a query fails but others succeed:

{
  "data": {
    "product": {
      "id": 42,
      "name": "Wireless Headphones",
      "relatedProducts": null
    }
  },
  "errors": [
    {
      "message": "Failed to load related products",
      "path": ["product", "relatedProducts"],
      "extensions": {
        "code": "INTERNAL_ERROR"
      }
    }
  ]
}

Always check for errors even when data is present.

Best Practices

  • Always check the errors array, not just the HTTP status code. Most GraphQL errors return HTTP 200.
  • Use extensions.code for programmatic error handling instead of parsing the message string.
  • Implement retry logic with exponential backoff for RATE_LIMITED and INTERNAL_ERROR responses.
  • Log the full error response including path and extensions to make debugging easier.
  • Validate input client-side before sending mutations to reduce VALIDATION_ERROR responses.

On this page