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.code | HTTP Status | Meaning & Recommended Action |
|---|---|---|
UNAUTHENTICATED | 200 / 401 | Missing, expired, or invalid JWT / secret key. Prompt sign-in or refresh session. |
FORBIDDEN | 200 / 403 | Authenticated actor lacks ownership, B2B Company Admin role, or Admin RBAC policy. |
NOT_FOUND | 200 / 404 | Target product, cart, order, quote, or customer does not exist in this store. |
BAD_USER_INPUT | 200 / 400 | Validation error on query arguments or mutation input (inspect extensions.field). |
PAYMENT_AUTHORIZATION_ERROR | 200 / 402 | Payment provider declined or failed to authorize the payment session. |
IDRABBIT_VERIFICATION_REQUIRED | 200 / 403 | Checkout blocked pending ID Rabbit identity/21+ verification—call createCartIdrabbitSession. |
RATE_LIMIT_EXCEEDED | 429 | Per-actor or per-IP Redis sliding-window rate limit (150 req/min) exceeded. Back off with jitter. |
QUERY_DEPTH_EXCEEDED | 200 | AST selection depth exceeded (10 on /graphql, 14 on /admin/graphql). Flatten selection sets. |
ALIAS_LIMIT_EXCEEDED | 200 | Query used more aliases than allowed (15 on /graphql, 30 on /admin/graphql). |
DIRECTIVE_LIMIT_EXCEEDED | 200 | Query used more directives than allowed (50 on /graphql, 75 on /admin/graphql). |
QUERY_TOO_LARGE | 413 | Request body exceeded payload limit (~105 KB on /graphql, 16 MiB on /admin/graphql). |
BATCH_LIMIT_EXCEEDED | 400 | Batched JSON array exceeded 5 operations. Split into separate requests. |
CSRF_PREFLIGHT_REQUIRED | 400 | GET /graphql request omitted a preflight header (X-Xclade-Request: true or X-Xclade-Publishable-Key). |
INTERNAL_SERVER_ERROR | 200 / 500 | Unexpected 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...');
}
}