# Handle errors (/docs/sdks/errors)



When a request fails, the SDK throws an error with the HTTP status and details from the API. Every error extends `PaperfulError`, with a class for each kind of error. Streamed operations, such as [uploading](/docs/sdks/papers/upload) and [streaming a search](/docs/sdks/search/query#stream-search-progress), throw the same errors when they fail midway.

## Catch errors [#catch-errors]

<Tabs groupId="language" items="[&#x22;JavaScript&#x22;]">
  <Tab value="JavaScript">
    ```ts
    import { NotFound } from "@paperful/sdk";

    try {
      await paperful.papers.get("00000000-0000-0000-0000-000000000000");
    } catch (error) {
      if (error instanceof NotFound) {
        console.log("Paper not found");
      } else {
        throw error;
      }
    }
    ```
  </Tab>
</Tabs>

## Error details [#error-details]

Every error includes:

| Field     | Description                                                                      |
| --------- | -------------------------------------------------------------------------------- |
| `status`  | The HTTP status.                                                                 |
| `name`    | The error's name, such as `"not-found"`. Also available as the `ErrorName` enum. |
| `message` | A description of what went wrong.                                                |
| `retry`   | `true` when the request can be retried.                                          |
| `many`    | For validation errors, the problem with each invalid field.                      |

<Tabs groupId="language" items="[&#x22;JavaScript&#x22;]">
  <Tab value="JavaScript">
    ```ts
    import { ValidationError } from "@paperful/sdk";

    try {
      await paperful.search.query("revenue", { next: cursor });
    } catch (error) {
      if (error instanceof ValidationError) {
        console.log(error.many);
      } else {
        throw error;
      }
    }
    ```
  </Tab>
</Tabs>

## Common errors [#common-errors]

| Status | Class                  | Name                     | Description                                                                                                 |
| ------ | ---------------------- | ------------------------ | ----------------------------------------------------------------------------------------------------------- |
| `400`  | `BadRequest`           | `bad-request`            | The request was invalid.                                                                                    |
| `400`  | `ValidationError`      | `validation`             | One or more parameters are invalid, such as an expired [cursor](/docs/api#pagination).                      |
| `401`  | `Unauthorized`         | `unauthorized`           | The [API key](/docs/platform/api-keys) is missing or invalid.                                               |
| `403`  | `PermissionDenied`     | `permission-denied`      | The API key can't access this resource.                                                                     |
| `404`  | `NotFound`             | `not-found`              | The resource doesn't exist.                                                                                 |
| `408`  | `TimedOut`             | `timed-out`              | The request took too long.                                                                                  |
| `409`  | `Conflict`             | `conflict`               | The request conflicts with the resource's current state.                                                    |
| `413`  | `EntityTooLarge`       | `entity-too-large`       | The file is [larger than your plan allows](/docs/platform/limits#papers).                                   |
| `415`  | `UnsupportedMediaType` | `unsupported-media-type` | The file type [isn't supported](/docs/platform/limits#supported-formats), or its name couldn't be inferred. |
| `422`  | `InvalidData`          | `invalid-data`           | The data couldn't be processed.                                                                             |
| `429`  | `TooManyRequests`      | `too-many-requests`      | You've hit a [rate limit](/docs/platform/limits#api-requests).                                              |
| `500`  | `InternalError`        | `internal-error`         | Something went wrong on Paperful's side.                                                                    |
| `501`  | `NotImplemented`       | `not-implemented`        | The operation isn't supported.                                                                              |
| `503`  | `ServiceUnavailable`   | `service-unavailable`    | Paperful is temporarily unavailable. Retry later.                                                           |

## Catch any API error [#catch-any-api-error]

Check for `PaperfulError` to handle every error from the API, and let other errors, such as network failures, through.

<Tabs groupId="language" items="[&#x22;JavaScript&#x22;]">
  <Tab value="JavaScript">
    ```ts
    import { PaperfulError } from "@paperful/sdk";

    try {
      await paperful.papers.upload({ file });
    } catch (error) {
      if (error instanceof PaperfulError) {
        console.log(error.status, error.name, error.message);
      } else {
        throw error;
      }
    }
    ```
  </Tab>
</Tabs>
