---
title: "Errors"
description: "Every error class that forges throws."
canonical_url: "https://forges.link/reference/errors"
---
# Errors

> Every error class that forges throws.

All errors extend [`ForgeError`](#forgeerror). Errors from a request carry `forge`, `instance`, `url` and `method`. A class has the properties of the classes it extends. See [Handle errors and rate limits](https://forges.link/guides/errors).

## `ForgeErrorContext`

Where an error happened: the forge, the instance and the request.

| Member | Type |
| --- | --- |
| `forge?` | [`ForgeKind`](https://forges.link/reference/data-model#forgekind) |
| `instance?` | [`ForgeInstance`](https://forges.link/reference/data-model#forgeinstance) |
| `url?` | `string` |
| `method?` | `string` |

## `ForgeError`

Base class for every error that forges throws.

**extends:** `Error`

```ts
new ForgeError(message: string, context: ForgeErrorContext = {}, options?: ErrorOptions)
```

| Parameter | Type | Description |
| --- | --- | --- |
| `message` | `string` |  |
| `context?` | [`ForgeErrorContext`](https://forges.link/reference/errors#forgeerrorcontext) | Defaults to `{}`. |
| `options?` | `ErrorOptions` |  |

| Member | Type | Description |
| --- | --- | --- |
| `forge?` | [`ForgeKind`](https://forges.link/reference/data-model#forgekind) | The forge that the request went to. |
| `instance?` | [`ForgeInstance`](https://forges.link/reference/data-model#forgeinstance) |  |
| `url?` | `string` |  |
| `method?` | `string` |  |

## `ForgeApiError`

The forge responded with an error.

**extends:** [`ForgeError`](https://forges.link/reference/errors#forgeerror)

```ts
new ForgeApiError(message: string, status: number, body: string, context?: ForgeErrorContext, options?: ErrorOptions)
```

| Parameter | Type |
| --- | --- |
| `message` | `string` |
| `status` | `number` |
| `body` | `string` |
| `context?` | [`ForgeErrorContext`](https://forges.link/reference/errors#forgeerrorcontext) |
| `options?` | `ErrorOptions` |

| Member | Type | Description |
| --- | --- | --- |
| `status` | `number` |  |
| `body` | `string` | Truncated response body, for diagnostics. |

## `NotFoundError`

A 404: the resource does not exist, or the credential cannot see it. Many forges respond the same way to both.

**extends:** [`ForgeApiError`](https://forges.link/reference/errors#forgeapierror)

## `AuthenticationRequiredError`

A 401, or a 403 with a request budget of zero (GitHub GraphQL), for a request
sent without credentials. A rejected credential is [`TokenRevokedError`](https://forges.link/reference/errors#tokenrevokederror).

**extends:** [`ForgeApiError`](https://forges.link/reference/errors#forgeapierror)

## `RateLimitedError`

The forge rate limited the request and a retry didn't help. Every rate limit rejects with this class, primary or secondary.

**extends:** [`ForgeApiError`](https://forges.link/reference/errors#forgeapierror)

```ts
new RateLimitedError(message: string, status: number, body: string, options: { resetAt?: Date, secondary?: boolean } & ForgeErrorContext = {}, errorOptions?: ErrorOptions)
```

| Parameter | Type | Description |
| --- | --- | --- |
| `message` | `string` |  |
| `status` | `number` |  |
| `body` | `string` |  |
| `options?` | [`{ resetAt?: Date, secondary?: boolean } & ForgeErrorContext`](https://forges.link/reference/errors#forgeerrorcontext) | Defaults to `{}`. |
| `errorOptions?` | `ErrorOptions` |  |

| Member | Type | Description |
| --- | --- | --- |
| `resetAt?` | `Date` | When to send again: after the forge's `retry-after`, or when a used-up budget resets. Absent when the forge names neither. |
| `secondary` | `boolean` | Whether the forge applied a secondary limit, such as a limit on concurrent requests or on content creation, rather than a used-up request budget. No remaining-request counter predicts it. |

## `TokenRevokedError`

The credential was revoked or expired.

**extends:** [`ForgeApiError`](https://forges.link/reference/errors#forgeapierror)

## `InsufficientScopeError`

The credential is valid but lacks the scope or permission for this call.

**extends:** [`ForgeApiError`](https://forges.link/reference/errors#forgeapierror)

```ts
new InsufficientScopeError(message: string, status: number, body: string, context?: ForgeErrorContext & Pick<InsufficientScopeError, 'acceptedScopes' | 'grantedScopes' | 'acceptedPermissionsRaw'>, options?: ErrorOptions)
```

| Parameter | Type |
| --- | --- |
| `message` | `string` |
| `status` | `number` |
| `body` | `string` |
| `context?` | `ForgeErrorContext & Pick<InsufficientScopeError, 'acceptedScopes' \| 'grantedScopes' \| 'acceptedPermissionsRaw'>` |
| `options?` | `ErrorOptions` |

| Member | Type | Description |
| --- | --- | --- |
| `acceptedScopes?` | `string[]` | Scopes that would allow the request, any one of them, where the forge names them (GitHub's `X-Accepted-OAuth-Scopes`). |
| `grantedScopes?` | `string[]` | Scopes the credential holds, where the forge reports them (GitHub's `X-OAuth-Scopes`). |
| `acceptedPermissionsRaw?` | `string` | Fine-grained permissions that would allow the request, verbatim, such as `issues=write` (GitHub's `X-Accepted-GitHub-Permissions`). |

## `ForbiddenReason`

Why the forge refused a request the credential is otherwise valid for.
`not_owner` is a resource that only the app that created it can change, such
as a GitHub check run that another app created. `unknown` is a 403 whose
body matched nothing recognised.

**one of:**

- `'org_restriction'`
- `'sso_required'`
- `'immutable_release'`
- `'resource_protected'`
- `'not_owner'`
- `'unknown'`

## `ForbiddenError`

The forge refused the request for a reason other than a missing scope or a
rate limit: an organisation policy, an SSO requirement, a protected
resource, a release the forge has marked immutable, or a resource that
belongs to another app. A missing scope is
[`InsufficientScopeError`](https://forges.link/reference/errors#insufficientscopeerror), and a rate limit [`RateLimitedError`](https://forges.link/reference/errors#ratelimitederror).

**extends:** [`ForgeApiError`](https://forges.link/reference/errors#forgeapierror)

```ts
new ForbiddenError(message: string, status: number, body: string, reason: ForbiddenReason, context?: ForgeErrorContext & { reasonRaw?: string, ssoUrl?: string }, options?: ErrorOptions)
```

| Parameter | Type |
| --- | --- |
| `message` | `string` |
| `status` | `number` |
| `body` | `string` |
| `reason` | [`ForbiddenReason`](https://forges.link/reference/errors#forbiddenreason) |
| `context?` | [`ForgeErrorContext & { reasonRaw?: string, ssoUrl?: string }`](https://forges.link/reference/errors#forgeerrorcontext) |
| `options?` | `ErrorOptions` |

| Member | Type | Description |
| --- | --- | --- |
| `reason` | [`ForbiddenReason`](https://forges.link/reference/errors#forbiddenreason) | Why the forge refused the request. |
| `reasonRaw?` | `string` | The forge's own wording, for diagnostics and for reasons that have no `ForbiddenReason`. |
| `ssoUrl?` | `string` | Where the user authorises the credential for the organisation, when `reason` is `sso_required` and the forge links it (GitHub's `X-GitHub-SSO`). |

## `ForgeTimeoutError`

A request or a pending merge exceeded `timeout`.

**extends:** [`ForgeError`](https://forges.link/reference/errors#forgeerror)

```ts
new ForgeTimeoutError(message: string, timeout: number, context?: ForgeErrorContext, options?: ErrorOptions)
```

| Parameter | Type |
| --- | --- |
| `message` | `string` |
| `timeout` | `number` |
| `context?` | [`ForgeErrorContext`](https://forges.link/reference/errors#forgeerrorcontext) |
| `options?` | `ErrorOptions` |

| Member | Type | Description |
| --- | --- | --- |
| `timeout` | `number` | The timeout that was exceeded, in milliseconds. |

## `StreamClosedError`

A `sources.stream()` connection closed or failed. Resume from `cursor`.

**extends:** [`ForgeError`](https://forges.link/reference/errors#forgeerror)

```ts
new StreamClosedError(message: string, cursor: string | undefined, context?: ForgeErrorContext, options?: ErrorOptions)
```

| Parameter | Type |
| --- | --- |
| `message` | `string` |
| `cursor` | `string \| undefined` |
| `context?` | [`ForgeErrorContext`](https://forges.link/reference/errors#forgeerrorcontext) |
| `options?` | `ErrorOptions` |

| Member | Type | Description |
| --- | --- | --- |
| `cursor?` | `string` | The cursor of the last event received. Pass it to `sources.stream()` to resume. |

## `ForgeNetworkError`

The request never got a response: DNS, TLS, connection refused or a proxy refusal.

**extends:** [`ForgeError`](https://forges.link/reference/errors#forgeerror)

## `UnsupportedOperationError`

The forge doesn't support the operation.

**extends:** [`ForgeError`](https://forges.link/reference/errors#forgeerror)

## `ReadOnlyError`

A write was called on a provider constructed with `readOnly: true`.

**extends:** [`UnsupportedOperationError`](https://forges.link/reference/errors#unsupportedoperationerror)

## `ContentNotTextError`

`contents.getFile` was asked for text and the file's bytes are not valid UTF-8.

**extends:** [`ForgeError`](https://forges.link/reference/errors#forgeerror)

## `UnknownForgeError`

A ref names a forge instance no registered provider serves.

**extends:** [`ForgeError`](https://forges.link/reference/errors#forgeerror)

## `UnresolvedThreadError`

The thread ref has no number, or is a kind the provider cannot address.

**extends:** [`ForgeError`](https://forges.link/reference/errors#forgeerror)

These exports are documented elsewhere: [`MergeBlockedError`](https://forges.link/reference/data-model#mergeblockederror), [`MergeConflictError`](https://forges.link/reference/data-model#mergeconflicterror), [`BranchMovedError`](https://forges.link/reference/data-model#branchmovederror), [`WebhookVerificationError`](https://forges.link/reference/data-model#webhookverificationerror), [`MergeMethodRequiredError`](https://forges.link/reference/data-model#mergemethodrequirederror).


## Sitemap

See the full [sitemap](https://forges.link/sitemap.md) for all pages.
