---
docId: doc_282cc503903c48a0b85f05a4b21eb2fe
title: Errors
description: "Identify and handle SDK errors by their class, status and code."
sidebarTitle: Errors
---

# Errors

Handle errors with `instanceof` and `error.code`. Use the code to decide what to do; the message explains the problem to the user.

For API errors, `error.code` matches `details.code` in the response.

```ts
import { ConflictError, PlaticApiError } from "platic-sdk";

try {
  await platic.agents.rollback(agent.id, { versionId: "v3" });
} catch (error) {
  if (error instanceof ConflictError && error.code === "NOT_PREVIOUSLY_PUBLISHED") {
    console.log("v3 was never published; nothing changed");
  } else if (error instanceof PlaticApiError) {
    console.error(`${error.request.operation}: ${error.status} ${error.code} ${error.message}`);
  } else {
    throw error;
  }
}
```

The codes are listed in [Errors](/api-reference/errors) and on each endpoint page.

## Error from the API

All SDK errors are instances of `PlaticError`. If the API returns an error response, you receive a `PlaticApiError` with these fields:

| Field | Type | What it is |
|---|---|---|
| `status` | number | The HTTP status. |
| `code` | string | The stable error code, such as `NOT_FOUND`. |
| `message` | string | A sentence for people. |
| `details` | object | Extra data for the code: `issues`, `available`, `status` and others. |
| `request` | object | `operation`, `method`, `path` and `attempts` (how many times it was sent). |
| `retryAfterMs` | number or null | The `Retry-After` of the answer, in milliseconds. |
| `wwwAuthenticate` | string or null | The `WWW-Authenticate` header of a 401, for OAuth clients. |

The class depends on the HTTP status:

| Status | Class | Notes |
|---|---|---|
| 400, 413 | `InvalidRequestError` | `issues` and `fields` name what was refused. |
| 401 | `AuthenticationError` | Missing, wrong, revoked or expired credential. |
| 403 | `PermissionDeniedError` | |
| 404 | `NotFoundError` | Also for something that belongs to another workspace. |
| 410 | `GoneError` | A subclass of `NotFoundError`. Also an expired conversation search (`SEARCH_SESSION_EXPIRED`). |
| 409 | `ConflictError` | Never retried, except two short-lived conflicts of [conversation actions](#conversation-errors). |
| 412 | `PreconditionFailedError` | `currentVersion`: the `expectedVersion` of a conversation action is out of date. |
| 422 | `InvalidConfigError` | A subclass of `InvalidRequestError`. |
| 429 | `RateLimitError` | `retryAfterMs` says how long to wait. |
| 500 | `InternalServerError` | |
| 502, 503, 504 | `ServiceUnavailableError` | |

Any other status is a plain `PlaticApiError`. An answer that is not the API's shape has `code: "UNEXPECTED_RESPONSE"`.

<span id="conversation-errors"></span>

## Conversation errors

Conversation calls use the same classes, with codes of their own. The full list is in [Errors in the API](/api-reference/errors#conversations).

```ts
import { ConflictError, PreconditionFailedError } from "platic-sdk";

const { data, meta } = await platic.conversations.get("conv_123", { fields: ["assigneeIds"] });
try {
  await platic.conversations.assignees.set(
    "conv_123",
    { assigneeIds: [...(data.assigneeIds ?? []), "ana@acme.com"] },
    { expectedVersion: meta.resourceVersion },
  );
  await platic.conversations.archive("conv_123");
} catch (error) {
  if (error instanceof PreconditionFailedError) {
    // Nothing changed: read the conversation again, decide again and repeat.
    console.log("It changed since it was read; current version:", error.currentVersion);
  } else if (error instanceof ConflictError && error.code === "CASE_OPEN") {
    console.log("Close these cases first:", error.caseIds);
  } else {
    throw error;
  }
}
```

| Class | Codes | What the error carries |
|---|---|---|
| `InvalidRequestError` | `INVALID_REQUEST`, `INVALID_FIELD`, `INVALID_INCLUDE`, `INVALID_FILTER`, `INVALID_CURSOR` | `issues`; `allowed` lists the accepted `fields` or `include` values. |
| `PermissionDeniedError` | `FORBIDDEN`, `INSUFFICIENT_SCOPE` | The credential can't read conversations, or can't change them. |
| `NotFoundError` | `CONVERSATION_NOT_FOUND`, `MESSAGE_NOT_FOUND`, `NOT_A_CONVERSATION` | A conversation out of the credential's reach answers like one that doesn't exist. |
| `GoneError` | `SEARCH_SESSION_EXPIRED` | Start the search again without `pageToken`. |
| `ConflictError` | `CASE_OPEN`, `CONVERSATION_ARCHIVED`, `CONVERSATION_SPAM`, `CONVERSATION_BUSY`, `CONVERSATION_CHANGED`, `STATUS_TRANSITION_NOT_ALLOWED`, `THREAD_CLOSED`, `AGENT_NOT_ACTIVE`, `NO_ACTIVE_AGENT`, `AGENT_STOPPING`, `ASSISTANT_CONTINUATION_INVALID`, `IDEMPOTENCY_KEY_REUSED`, `IDEMPOTENCY_IN_PROGRESS` | `caseIds` for `CASE_OPEN`. |
| `PreconditionFailedError` | `VERSION_MISMATCH` | `currentVersion`. Never retried. |
| `InvalidConfigError` | `UNKNOWN_TAG`, `TOO_MANY_TAGS`, `INVALID_ASSIGNEE`, `TOO_MANY_ASSIGNEES` | `unknownTags` (and `details.availableTags`), `invalidAssigneeIds`. |
| `ServiceUnavailableError` | `SEARCH_UNAVAILABLE`, `CONTINUE_FAILED`, `ACTION_FAILED` | `details.retryable: true`. |

- **The SDK retries some of them for you.** `SEARCH_UNAVAILABLE`, `CONTINUE_FAILED` and `ACTION_FAILED` are retried like any other `503`, and an action keeps the same request on every attempt, so it is applied once. `CONVERSATIONS_RETRYABLE_ERRORS` lists these codes.
- **Two conflicts are asked again**, up to `maxRetries` times: `IDEMPOTENCY_IN_PROGRESS` (an earlier attempt of the same call is still running) and, for `resume` and `wait`, `AGENT_STOPPING` (a previous reply is still stopping). Every other `ConflictError` is thrown at once.
- **A bulk call doesn't throw for one conversation.** Each failed item has `ok: false` and its `error.code`.

## Errors without an answer

| Class | When |
|---|---|
| `PlaticConnectionError` | No answer arrived. A change may have been applied: read the resource before trying again. |
| `PlaticTimeoutError` | A subclass of `PlaticConnectionError`. Every attempt exceeded `timeoutMs`. |
| `PlaticAbortError` | Your own `signal` ended the call. It is not retried. The signal's reason is the `cause`. |
| `PlaticUsageError` | The SDK cannot send the call: a missing id, an option out of range, a missing `apiKey`. Nothing was sent. |

## Errors of the waits and uploads

| Class | When |
|---|---|
| `FileJobTimeoutError` | The wait for `files.waitForJob` expired. Includes `lastJob`, `fileId`, `uploadId` and `waitedMs`. The job continues. |
| `EvalRunTimeoutError` | The wait for `agents.evals.runs.wait` expired. Includes `lastLaunch`. The run continues. |
| `ChannelConnectionTimeoutError` | The wait for `channels.connections.wait` expired. Includes `lastConnection`. |
| `PlaticUploadError` | The bytes of a large file did not reach their upload session. Has `fileId`, `uploadId` and the storage `status`. |
| `WebhookVerificationError` | A webhook delivery failed verification. Has `reason`. See [Webhooks](/sdk/webhooks). |

A file job that fails is returned, not thrown: check `job.status === "failed"` and read `job.error`.

## Validation errors

`InvalidRequestError` lists each problem in `error.issues`, as `{ path, message }`:

```ts
import { InvalidRequestError } from "platic-sdk";

try {
  await platic.agents.create({ name: "" });
} catch (error) {
  if (error instanceof InvalidRequestError) {
    for (const issue of error.issues) console.error(`${issue.path.join(".")}: ${issue.message}`);
  } else {
    throw error;
  }
}
```

## Handle the common cases

```ts
import { NotFoundError, PlaticConnectionError, RateLimitError } from "platic-sdk";

try {
  await platic.agents.publish(agentId);
} catch (error) {
  if (error instanceof NotFoundError) {
    console.log("That agent does not exist in this workspace");
  } else if (error instanceof RateLimitError) {
    console.log(`Slow down; try again in ${error.retryAfterMs ?? 0} ms`);
  } else if (error instanceof PlaticConnectionError) {
    // The publish may have gone through: read before you repeat it.
    const { publication } = await platic.agents.publication.get(agentId);
    console.log("Live version:", publication.versionId);
  } else {
    throw error;
  }
}
```

You can receive `RateLimitError` after retries run out, if the call isn't retried, or if `Retry-After` exceeds the allowed wait. See [Retries](/sdk/retries).

<span id="secrets-are-never-in-an-error"></span>

## Data the SDK hides

If a response or network error includes your API key, a secret's `value` or a webhook's signing secret, the SDK replaces it with `[REDACTED]` before creating the error message and details.

## Next steps

- [Retries](/sdk/retries)
- [Errors in the API](/api-reference/errors)
- [Types](/sdk/types): `ApiErrorCode`, `ConversationsErrorCode` and `ApiErrorDetails`.
