> ## Documentation Index
> Fetch the complete documentation index at: https://developers.circularo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Handle errors

Every failed request returns the same JSON envelope, whatever went wrong. This guide reads that envelope on two common failures — two requests in total — and turns it into something your code can branch on.

## Step 1: Read the envelope of a missing resource

Request a document that does not exist:

```http Request theme={null}
GET /documents/QvT8kXw2NcR5mZb4PdYj
Authorization: Bearer YOUR_API_KEY
```

```http Response theme={null}
HTTP/2 404

{
  "status": 404,
  "type": "DOCUMENT:NOT_FOUND",
  "message": "Document not found",
  "requestId": "a17c4e923b5d4f80b6e92d8c5a1f7e43"
}
```

The `type` is machine-readable — branch on it rather than on the `message`, which is human-readable and may be reworded. New types appear over time, so handle a `type` your code does not know by its HTTP status. Quote the `requestId` when contacting support; it identifies this exact request in Circularo's logs.

The part of the `type` before the colon is a namespace — a domain one such as `DOCUMENT`, or the generic `RESOURCE` where no dedicated one applies, so a missing transaction reports `RESOURCE:NOT_FOUND`. For documents, folders, groups and metadata definitions you cannot see, the answer is `404`, exactly as if they did not exist; `403` means you are not allowed to do this — a missing permission, an operation reserved for administrators, or something you can see but may not change. Files are the exception: an inaccessible file answers `403`.

## Step 2: Read the envelope of an invalid request

Send a request that fails validation:

```http Request theme={null}
GET /documents?limit=0
Authorization: Bearer YOUR_API_KEY
```

```http Response theme={null}
HTTP/2 400

{
  "status": 400,
  "type": "VALIDATION:INPUT_INVALID",
  "message": "Invalid query parameters: \"limit\" must be greater than or equal to 1.",
  "requestId": "5e28c7a190d44b3f8a6c1f7e42d95b03",
  "details": {
    "errors": [
      {
        "location": "query",
        "path": "limit",
        "message": "\"limit\" must be greater than or equal to 1"
      }
    ]
  }
}
```

Same envelope, different class: a `4xx` with a validation type means your request needs fixing before a retry makes sense, while a `404` may just mean "not yet" or "no longer". Server-side failures (`5xx`) and throttling (`429`, after its `Retry-After`) are the classes worth retrying — see [Retry requests safely](https://developers.circularo.com/guides/robust-integrations/idempotency.md) for doing that safely.

When the request does not match the operation's schema, as here, the envelope also lists every problem in `details.errors` — the part of the request it was found in (`location`: `body`, `query`, `path` or `headers`), the property's `path` and a `message` — so your code can point at the exact value to fix. A request that is well-formed but breaks a rule spanning several values, such as a field placed beyond the document's last page, is described by the `message` alone.

Two statuses can answer any call, whichever statuses its endpoint lists, because they concern your account rather than the request: `402` when the subscription your account is covered by is not active, and `428` when the account has not been activated yet — someone first has to activate it. Retrying does not help until the cause is resolved. An operation that consumes your subscription's capacity — such as creating documents, transactions or members, sealing or sending an SMS — also answers `402` when that capacity is used up.

> [!NOTE]
>
> When you exceed the rate limit, the envelope arrives with status `429` and a `Retry-After` header telling you how many seconds to wait before retrying.

## Complete example

One wrapper that turns every failure into the same typed error, as a Node.js script. Everything above it in your integration can then branch on `type`, and on `status` for a type it does not know.

```js theme={null}
// your environment's base URL
const BASE_URL = "https://sandbox.circularo.com/api/v2";
const API_KEY = "YOUR_API_KEY";

const call = async (method, path, body) => {
  const res = await fetch(`${BASE_URL}${path}`, {
    method: method,
    headers: {
      "Authorization": `Bearer ${API_KEY}`,
      "Content-Type": "application/json"
    },
    body: (body === undefined) ? undefined : JSON.stringify(body)
  });
  if (res.ok) {
    return (res.status === 204) ? null : await res.json();
  }

  const envelope = await res.json();
  console.error(`Request ${envelope.requestId} failed with ${envelope.status}`);
  if (res.status === 429) {
    console.error(`Rate limited, retry in ${res.headers.get("Retry-After")}s`);
  }

  // the whole envelope travels with the error, so callers can branch on its type
  throw Object.assign(new Error(envelope.message), envelope);
};

try {
  await call("GET", "/documents/QvT8kXw2NcR5mZb4PdYj");
} catch (error) {
  if (error.type === "DOCUMENT:NOT_FOUND") {
    console.log("Nothing to do — the document is gone");
  } else {
    throw error;
  }
}
```

## Next steps

* Retry the failures worth retrying, without creating duplicates — [Retry requests safely](https://developers.circularo.com/guides/robust-integrations/idempotency.md).
* Handle the `412` that guards a concurrent write — [Guard concurrent writes](https://developers.circularo.com/guides/robust-integrations/concurrency.md).
* The statuses specific to each endpoint are listed in the API reference.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.