Skip to Content
Athanor

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.codeWhereCarriesWhat to do
Unauthenticatedthe request (401)—Send a bearer token.
InsufficientScopethe fieldscopeMint a client with that scope, or stop selecting the field.
OrderNotInStageadvanceOrdernextStepsTake one of the steps named; read the record again if unsure.
StepRefusedadvanceOrderreasonThe step's own refusal; see below.
IdempotencyConflicta mutation—The key was used for a different request; use a new key.
DocumentUnknownthe request—The documentId is not registered for this client; register it, or send the text on sandbox.
TrustedOnlythe request—The client accepts registered documents only on live; send documentId.
DocumentInvalidregisterDocumentproblemsThe document does not validate against the schema; the validator's words say where.
WorkloadRequiredthe registry—Registration needs a client's token, not a session.
EndpointUrlRefusedregisterWebhook—HTTPS only, no credentials in the URL, a host that resolves to public addresses.
RATELIMITEDthe request (429)Retry-AfterWait as the header says; the SDK does. See Budgets.
INTERNALanywhere—Ours. Retry once; tell us if it stays.

Step refusals

StepRefused carries reason:

reasonStepMeaning
quote_movedlockPricesThe desk's indicative total differs from expectedAllIn. Read the record, show the new total, lock again with it.
authorized_maximum_mismatchissueDirectionThe letter would state a maximum other than authorizedMaximum.
recipient_mismatchsendDirectionThe holder on record is not recipientEmail.
market_closedlockPricesA metal on the sheet has no market right now; pricing.closed names it.
pairing_not_activeanyThe dealer's pairing with the holder's custodian is not active.
depository_not_enabledanyThe 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.

On this page