xcladeDocs
Storefront GraphQL

Error Handling

Standardized GraphQL error extensions, Go ErrorPresenter wire codes, and recovery patterns

Error Handling

All GraphQL errors returned by /graphql and /admin/graphql pass through the Go ErrorPresenter (graph/middleware/security.go), ensuring consistent machine-readable extensions.code values and safe error masking in production.


Response Format

{
  "data": null,
  "errors": [
    {
      "message": "query depth 12 exceeds maximum allowed depth 10",
      "path": ["products"],
      "extensions": {
        "code": "QUERY_DEPTH_EXCEEDED"
      }
    }
  ]
}

When a validation error targets a specific input field, extensions.field is included automatically.


Wire Error Codes

extensions.codeHTTP StatusMeaning & Recommended Action
UNAUTHENTICATED200 / 401Missing, expired, or invalid JWT / secret key. Prompt sign-in or refresh session.
FORBIDDEN200 / 403Authenticated actor lacks ownership, B2B Company Admin role, or Admin RBAC policy.
NOT_FOUND200 / 404Target product, cart, order, quote, or customer does not exist in this store.
BAD_USER_INPUT200 / 400Validation error on query arguments or mutation input (inspect extensions.field).
PAYMENT_AUTHORIZATION_ERROR200 / 402Payment provider declined or failed to authorize the payment session.
IDRABBIT_VERIFICATION_REQUIRED200 / 403Checkout blocked pending ID Rabbit identity/21+ verification—call createCartIdrabbitSession.
RATE_LIMIT_EXCEEDED429Per-actor or per-IP Redis sliding-window rate limit (150 req/min) exceeded. Back off with jitter.
QUERY_DEPTH_EXCEEDED200AST selection depth exceeded (10 on /graphql, 14 on /admin/graphql). Flatten selection sets.
ALIAS_LIMIT_EXCEEDED200Query used more aliases than allowed (15 on /graphql, 30 on /admin/graphql).
DIRECTIVE_LIMIT_EXCEEDED200Query used more directives than allowed (50 on /graphql, 75 on /admin/graphql).
QUERY_TOO_LARGE413Request body exceeded payload limit (~105 KB on /graphql, 16 MiB on /admin/graphql).
BATCH_LIMIT_EXCEEDED400Batched JSON array exceeded 5 operations. Split into separate requests.
CSRF_PREFLIGHT_REQUIRED400GET /graphql request omitted a preflight header (X-Xclade-Request: true or X-Xclade-Publishable-Key).
INTERNAL_SERVER_ERROR200 / 500Unexpected server error (masked in production to avoid leaking internals).

Handling Errors with @xclade/sdk

import { XcladeError, FetchError } from '@xclade/sdk';

try {
  const order = await xclade.store.completeCart(cartId);
} catch (err) {
  if (err instanceof XcladeError) {
    switch (err.code) {
      case 'IDRABBIT_VERIFICATION_REQUIRED': {
        const res = await xclade.store.query(
          `mutation($id: ID!) { createCartIdrabbitSession(cart_id: $id) { idrabbit { verification_url } } }`,
          { id: cartId },
        );
        window.location.href = res.createCartIdrabbitSession.idrabbit.verification_url;
        break;
      }
      case 'PAYMENT_AUTHORIZATION_ERROR':
        showToast('Your card could not be authorized. Please try another payment method.');
        break;
      default:
        showToast(err.message);
    }
  } else if (err instanceof FetchError && err.status === 429) {
    showToast('Too many requests. Retrying shortly...');
  }
}

On this page