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

# Handling errors

> Catch OnlyFansAPIError, read its status and body, and know what the common OnlyFans error responses mean.

Every non-2xx response throws `OnlyFansAPIError`:

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { OnlyFansAPIError } from "onlyfanskit";

try {
  await of.users.retrieve("nonexistent_username");
} catch (err) {
  if (err instanceof OnlyFansAPIError) {
    console.log(err.status); // e.g. 404
    console.log(err.body);   // raw response body
    console.log(err.path);   // the request path
  }
}
```

## What the common errors mean

| Status | When you'll see it                                         | What to do                                                        |
| ------ | ---------------------------------------------------------- | ----------------------------------------------------------------- |
| 400    | `add a payment card` (code 106)                            | Subscribing requires a card on file, even for free creators.      |
| 400    | `User cannot comment` / `can't add this post to bookmarks` | The account isn't age-verified. Many fan-side actions require it. |
| 401    | Session expired or revoked                                 | Reconnect the account with a fresh session.                       |
| 403    | Not subscribed, or a creator-only endpoint                 | Subscribe first, or call from the creator's account.              |
| 404    | Resource not found                                         | Check the id or username.                                         |
| 429    | Rate limited                                               | Back off and retry. See [Rate limiting](/platform/rate-limiting). |

## Exposing errors over HTTP

When you surface SDK results through your own HTTP API, convert thrown errors
into [RFC 9457 problem documents](/platform/errors) so your callers — including
AI agents — get a parseable, actionable contract instead of a raw stack trace:

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { errorResponse } from "onlyfanskit";

try {
  return new Response(JSON.stringify(await of.posts.create(body)));
} catch (err) {
  return errorResponse(err, { instance: request.url });
}
```

`errorResponse` classifies the failure (age verification, billing, access,
rate limit, and more) and produces the right problem `type` automatically.
