Refusals
Read the errors array even on a 200. Every refusal has a stable code, and most carry the fact you need to recover.
GraphQL answers a document, not a request. A field the token may not read, an order not in the stage a step needs, a document the client never registered: each is an error at its path with data still carrying what did resolve. The HTTP status is 200. Only a malformed body (400), a missing credential (401) or a spent budget (429) refuses the request itself.
{
"data": {
"viewer": {
"organization": {
"name": "Buckler Co",
"clients": { "totalCount": 12 },
"orders": null
}
}
},
"errors": [
{
"message": "The token does not hold dealer:orders:read.",
"path": ["viewer", "organization", "orders"],
"extensions": {
"code": "InsufficientScope",
"scope": "dealer:orders:read"
}
}
]
}The SDK turns a response with errors into an AthanorApiError whose code, reason and data are these.
Codes
extensions.code | Where | Carries | What to do |
|---|---|---|---|
Unauthenticated | the request (401) | — | Send a bearer token. |
InsufficientScope | the field | scope | Mint a client with that scope, or stop selecting the field. |
OrderNotInStage | advanceOrder | nextSteps | Take one of the steps named; read the record again if unsure. |
StepRefused | advanceOrder | reason | The step's own refusal; see below. |
IdempotencyConflict | a mutation | — | The key was used for a different request; use a new key. |
DocumentUnknown | the request | — | The documentId is not registered for this client; register it, or send the text on sandbox. |
TrustedOnly | the request | — | The client accepts registered documents only on live; send documentId. |
DocumentInvalid | registerDocument | problems | The document does not validate against the schema; the validator's words say where. |
WorkloadRequired | the registry | — | Registration needs a client's token, not a session. |
EndpointUrlRefused | registerWebhook | — | HTTPS only, no credentials in the URL, a host that resolves to public addresses. |
RATELIMITED | the request (429) | Retry-After | Wait as the header says; the SDK does. See Budgets. |
INTERNAL | anywhere | — | Ours. Retry once; tell us if it stays. |
Step refusals
StepRefused carries reason:
reason | Step | Meaning |
|---|---|---|
quote_moved | lockPrices | The desk's indicative total differs from expectedAllIn. Read the record, show the new total, lock again with it. |
authorized_maximum_mismatch | issueDirection | The letter would state a maximum other than authorizedMaximum. |
recipient_mismatch | sendDirection | The holder on record is not recipientEmail. |
market_closed | lockPrices | A metal on the sheet has no market right now; pricing.closed names it. |
pairing_not_active | any | The dealer's pairing with the holder's custodian is not active. |
depository_not_enabled | any | The depository is not enabled for the pairing. |
Reading a refusal in code
try {
await athanor.execute(AdvanceOrderDocument, { input });
} catch (error) {
if (error instanceof AthanorApiError) {
switch (error.code) {
case "StepRefused":
/* error.reason */ break;
case "OrderNotInStage":
/* error.errors[0].extensions.nextSteps */ break;
case "InsufficientScope":
/* error.errors[0].extensions.scope */ break;
}
}
}error.errors is the whole array; code and reason read the first. error.data is what resolved beside the refusal, typed as a partial of the document's result.
The order's machine
Draft an order, then advance it one step at a time. The record names the steps that are legal right now, and a refusal names what it was waiting for.
Webhooks
The order's facts pushed to your endpoint as they happen, on the Standard Webhooks spec, signed with a key you can verify offline, retried for three days, replayable from Settings.