Errors and limits
Every Kaladan API reports trouble in two different ways, and telling them apart is the first thing a client has to get right.
Request errors: it never ran
Section titled “Request errors: it never ran”The operation did not run. The response has a top-level errors array and
data: null, and an HTTP status that says why. Fix the request, or retry it
when the code says retrying helps.
{ "data": null, "errors": [ { "message": "This request needs more points than are available.", "extensions": { "code": "MAX_COST_EXCEEDED" } } ]}The codes are a closed list. A client can switch on all of them:
| Code | What it means | What to do |
|---|---|---|
BAD_REQUEST | The document or its variables are malformed. | Fix the request. |
UNAUTHENTICATED | No credential, an expired one, or one for another shop. | Refresh the token, or check the host. |
ACCESS_DENIED | The credential is valid but may not do this. | Do not retry. |
SCOPE_ESCALATION | An app asked for fields outside its grant. missing lists which scope each one needs. | Ask the merchant to approve a version that declares them. |
NOT_FOUND | The thing addressed does not exist, or this caller may not know it does. | Do not retry. |
THROTTLED | Too many requests. | Wait for Retry-After. |
MAX_COST_EXCEEDED | The query costs more than the bucket holds. | Wait for Retry-After, or ask for less. |
SHOP_UNAVAILABLE | The shop is not serving: extensions.reason is STORE_LOCKED or SUSPENDED. | Show the shop as closed. |
API_VERSION_UNSUPPORTED | The version in the path is not served. Today this arrives as a plain 404. | Move to a supported version. |
INTERNAL | Something failed on Kaladan’s side. | Retry with backoff; report it if it persists. |
Every response carries an X-Request-Id header. Log it: it is what to quote
when you ask for help.
User errors: it ran, and said no
Section titled “User errors: it ran, and said no”The operation ran, decided, and declined: a quantity over the stock, a code that expired, a field that failed validation. These arrive on a 200, inside the mutation’s payload:
mutation { cartLinesAdd(cartId: "…", lines: […]) { cart { totalQuantity } userErrors { code field params message } }}- A non-empty
userErrorsmeans nothing changed. There are no partial writes to reconcile. - Switch on
codeand readparams.messageis English, for your logs. It is never meant for a buyer or a merchant; write your own words from the code. fieldis a path into the input you sent, so a form can mark the field that was refused.
The shared codes are REQUIRED, MIN_LENGTH, MAX_LENGTH, PATTERN,
OUT_OF_RANGE, ENUM, LIST_SIZE, INVALID, INCONSISTENT, NOT_FOUND,
FORBIDDEN, EXPIRED, UNAVAILABLE, INSUFFICIENT_STOCK, CODE_INVALID,
NOT_APPLICABLE, INVALID_STATE, IDEMPOTENCY_CONFLICT and RATE_LIMITED.
Cart mutations can also return warnings on success: a quantity trimmed to
stock, a line dropped because its product was unpublished. Read them, or you
show a buyer a cart they did not agree to.
Cost, not request counts
Section titled “Cost, not request counts”Each credential has a bucket of 2,000 points that refills at 100 points a second. A request is charged before it runs, from the query document itself:
- each object field costs 1;
- a connection costs its
firstorlast, and nesting multiplies; - a scalar leaf costs nothing.
What the response did not use is refunded afterwards, and every response says what happened:
{ "extensions": { "cost": { "requestedQueryCost": 152, "actualQueryCost": 46, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1954, "restoreRate": 100 } } }}Asking for first: 250 and drawing ten is charged for 250 up front, because the
capacity was reserved for 250. Ask for the page you will show.
Retrying safely
Section titled “Retrying safely”Mutations that move money or stock (cartCheckoutStart, for one) take an
idempotencyKey. Send the same key when you retry and the operation runs
at most once. Keys are remembered for 24 hours, and reusing one with a
different input is IDEMPOTENCY_CONFLICT.
Lists are cursor-based: first and after forward, last and before
backward, never both. A page holds at most 250 items, and asking for more is
OUT_OF_RANGE rather than a quiet truncation. Conventions
explains sorting and why changing the sort retires your cursor.