KausateKausate Docs

Handle errors

Branch on error codes, act on each code's group, and read failures from async orders, webhooks and MCP.

Use this when you build the error handling around your Kausate calls: what to tell your user, when to try again, and where the code sits when the failure arrives in an order result, a webhook or an MCP tool call. Once it is done, every failure lands in a branch you chose, and an unknown code falls through to a safe default. What the error body, code and status mean: Errors.

1. Branch on the code prefix

Codes are published at full depth, so match the prefix you care about rather than the whole code. Handle a whole family at once:

// Handle every "company not found" variant, however specific.
if (error.code.startsWith("company.not_found")) {
  showCompanyNotFound();
}

// Or split into segments and switch on the namespace.
const [namespace] = error.code.split(".");
if (namespace === "company") {
  showCompanyProblem();
}
if error["code"].startswith("document.not_found"):
    mark_document_unavailable()

Prefix matching is safe because several conditions share one code by design, and a published code never changes. New codes can be added, so always keep a default branch. code is never absent: an unclassified failure returns internal.unexpected. The namespaces and every code are in Error codes.

2. Act on the code's group

We retry temporary failures ourselves before we answer you: when a register is slow, briefly unavailable or too busy, we try again on our side, and an async order keeps trying while its status is running. An error you receive is what remains after those retries, so it carries no retry hint. Each code belongs to one of four groups, by what you do next:

GroupWhat to do
Fix the requestChange the request, your API key, your credits or your settings, then send it again. The same request fails the same way.
Try again nowSend the same request again straight away. Nothing was charged.
Try again laterSend the same request again later, waiting longer after each failure. If it keeps failing, contact support and quote request_id.
FinalRetrying will not change the answer. Show it to your user, or make the different call the row names.

The group follows from the code, not from the status alone: map each code your client handles to its group in Error codes, and treat an unknown code as final. Prefer async when a user is not waiting on the result, because an async order keeps retrying a register that is briefly unavailable.

3. Read failures from async orders and webhooks

For an async order the HTTP response is a 200; the failure is in the payload. Check status, then read error and, for versions that include it, code. Failed order results and their webhook payloads include error in API version 2025-04-01; API version 2026-05-01 and later also include code.

{
  "status": "failed",
  "error": "Data source temporarily unavailable",
  "code": "source.unavailable"
}

status is one of six values. Four of them are terminal failures, and all four carry error and code, so switch on the full set and treat anything you do not recognize as terminal rather than as "still running":

statusTerminal?error / codeWhat happened
runningnoabsentStill processing: keep polling, or wait for the webhook
completedyesabsentSuccess; the payload is in result
failedyespresentThe order ran and failed: branch on code
canceledyespresentThe order was canceled and stopped cleanly
terminatedyespresentThe order was forcefully stopped
timedOutyespresentThe order ran past its time limit
switch (order.status) {
  case "running":
    return poll();
  case "completed":
    return use(order.result);
  default:
    // failed | canceled | terminated | timedOut: all carry code + error
    return handle(order.code, order.error);
}

Webhook payloads use the same fields for their payload version. Read the Kausate-Version delivery header to tell which version a delivery uses.

4. Read the code from MCP

The MCP server publishes the same codes, as data wherever the protocol has somewhere to put them:

MCP surfaceWhere the code appears
get_order_resultthe code field of the returned object, beside error
tasks/get on a failed taskthe task's error.data = { "code": … }
a JSON-RPC error (tasks/* failures)error.data = { "code": … }

A failing tool call is the one exception. MCP delivers it as a plain text block with no structured channel, so the code comes as a marker at the very start of the message:

[code=document.temporarily_unavailable] Document is temporarily unavailable — if you need help, contact the Kausate support team at support@kausate.com. Quote Order ID: ord_…; Request ID: req_….

Match it anchored, with /^\[code=([a-z0-9_.]+)\] /, and treat the rest of the string as display text. The marker is always first when present; it is absent only when there is no code to report.

One MCP failure comes before the marker: argument validation. If a tools/call names an argument the tool does not declare, or sends one of the wrong type, the call is rejected before the tool runs, with validation text and no [code=…] prefix. Treat an unmarked tool error as a malformed call; the message names the offending argument.

Check that it worked

Call the sandbox error band, whose companies always fail the same way. A sync company report for Sandbox Vanished GmbH returns 404 with company.not_found:

curl -X POST "https://api.kausate.com/v2/companies/report/sync" \
  -H "X-API-Key: $KAUSATE_API_KEY" \
  -H "Kausate-Version: 2026-08-01" \
  -H "Content-Type: application/json" \
  -d '{ "kausateId": "co_zz_4eIiedDTNj93xHhsCyieE" }'

Your handler should take its company.not_found branch and not retry. Place the same order async, and the failed order result should reach the same branch through status and code.

  • Errors: the error body, the status set, and how status and code differ.
  • Error codes: every published code, grouped by what to do.
  • Limits: the bounds behind 408 and 429.
  • Webhooks: receive order results, including failed ones.
  • AI assistants: connect the MCP server.

Last updated on

On this page