# NoClickError

> Errors: every refusal the API makes, as a typed class that says what to do next.

The server renders every refusal as `{"error": {"type", "message", "next_step", ...details}}`; `type` picks the class here (the same names
and HTTP statuses the API uses). Extra keys land in `details` and read as
attributes: `err.connect_url`, `err.existing_id`.

## NoClickError

```typescript
class NoClickError extends Error
```

Base class for every NoClick platform error.

| Attribute | Type | Description |
| --- | --- | --- |
| `type` | `string` |  |
| `httpStatus` | `number | null` |  |
| `nextStep` | `string | null` |  |
| `details` | `JsonObject` |  |
| `status` | `number | null` |  |
| `requestId` | `string | null` |  |
| `attempts` | `number | null` | How many times the client sent the call before this error (1 + its retries); null when no request raised it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### NoClickError.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### NoClickError.errorType

```typescript
static errorType: string
```

## Offer

```typescript
interface Offer
```

One way past a refusal for money: a link a person opens to pay, no sign-in needed. Hand them `url`.

| Attribute | Type | Description |
| --- | --- | --- |
| `kind` | `string` | `plan` (a plan that includes what was refused), `funds` (an amount added to the balance) or `topup` (a monthly add-on, on the older plans). |
| `label` | `string` | What it buys, in words: `the Plus plan, billed monthly`. |
| `priceUsd` | `number` |  |
| `url` | `string` |  |
| `expiresAt` | `Date | null` | When the link stops working; refused again before then, the same link comes back. |
| `operation` | `Operation<JsonObject>` | The `payment` operation the link settles: `wait()` resolves once it's paid, and rejects with `OperationExpired` if it never is. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## InvalidRequest

```typescript
class InvalidRequest extends NoClickError
```

The request is malformed or a value is out of range; `field` names the argument when there is one.

Error type `invalid_request`, HTTP 400.

### InvalidRequest.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### InvalidRequest.errorType

```typescript
static errorType: string
```

## Unauthenticated

```typescript
class Unauthenticated extends NoClickError
```

No key was sent, or the key or session token isn't valid (revoked, expired, or not a platform key).

Error type `unauthenticated`, HTTP 401.

### Unauthenticated.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### Unauthenticated.errorType

```typescript
static errorType: string
```

## PaymentRequired

```typescript
class PaymentRequired extends NoClickError
```

Your account can't pay for this: `balanceUsd` is what's left and `requiredUsd` what the call
needs, in US dollars. `offers` are links a person opens to add funds or change plan; retry once
one is paid. A model provider's account out of funds (your own key) throws it too, with
`details.reason` `"provider_out_of_funds"`. A deployed app's paid call names the app in
`details.project` and `details.project_id` (invite-only beta).

    if (err instanceof PaymentRequired) for (const offer of err.offers) console.log(offer.label, offer.url);

Error type `payment_required`, HTTP 402.

| Attribute | Type | Description |
| --- | --- | --- |
| `balanceUsd` | `number | undefined` |  |
| `requiredUsd` | `number | undefined` |  |

### PaymentRequired.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### PaymentRequired.errorType

```typescript
static errorType: string
```

## PlanRequired

```typescript
class PlanRequired extends NoClickError
```

The account's plan doesn't allow this: plans cap some resources. `offers` are links to the plans that do.

Error type `plan_required`, HTTP 402.

### PlanRequired.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### PlanRequired.errorType

```typescript
static errorType: string
```

## PriceExceeded

```typescript
class PriceExceeded extends NoClickError
```

It would cost more than the ceiling you set (`max_monthly_usd` on `PhoneNumber.buy`).

Error type `price_exceeded`, HTTP 402.

### PriceExceeded.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### PriceExceeded.errorType

```typescript
static errorType: string
```

## ApprovalRequired

```typescript
class ApprovalRequired extends NoClickError
```

A policy wants a person to approve this call first. The approval request is
already out; wait on it, then retry with `approvalId`:

    if (err instanceof ApprovalRequired && (await err.operation?.wait()))
      await gmail.run("send_email_message", args, { approvalId: err.approvalId });

A call NoClick holds for the account's owner (a purchase, a deletion that can't be undone, a change from an
agent or a connected app) waits on the owner instead, who approves it from the link NoClick sends them
(`details.sent_to` says where). NoClick makes the call itself once they do: wait on `operation` for its
answer, and don't retry it.

Error type `approval_required`, HTTP 402.

| Attribute | Type | Description |
| --- | --- | --- |
| `approvalId` | `string | undefined` |  |
| `approveUrl` | `string | undefined` | The page where the approver answers; set only when the approver is the one the call is made for. |
| `operation` | `HumanRequest<boolean> | Operation<JsonObject> | null` | The approval as an operation: `wait()` resolves to `true` once approved. `null` when the call's credential can't read it: a user's session, or a key pinned to them, for a call someone else approves.  A call NoClick holds for the account's owner is the held call itself instead (`operationId`): NoClick makes the call once they approve, so there's nothing to retry, and `wait()` resolves to `{ status, response }`, the call's HTTP status and its answer. It throws `PolicyDenied` if they decline, and `Expired` if nobody answers in time. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### ApprovalRequired.operationId

```typescript
operationId: string | undefined
```

The approval's operation id (`Operation.fromId(id).wait()` resolves to a boolean).

### ApprovalRequired.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### ApprovalRequired.errorType

```typescript
static errorType: string
```

## SpendCapExceeded

```typescript
class SpendCapExceeded extends NoClickError
```

A monthly spend cap (`scope`: key, user, agent, ...) is used up. A deployed app's paid
call names the app in `project` and `project_id`, with `scope` `project` when it's
the app's own `budget_usd_per_month`.

Error type `spend_cap_exceeded`, HTTP 402.

| Attribute | Type | Description |
| --- | --- | --- |
| `cap` | `number | undefined` |  |
| `spent` | `number | undefined` |  |
| `scope` | `string | undefined` | Which cap tripped: `key`, `user`, `agent`, `project` (a deployed app's own budget), ... An app's paid call names the app in `details.project` and `details.project_id`. |

### SpendCapExceeded.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### SpendCapExceeded.errorType

```typescript
static errorType: string
```

## SpendingPaused

```typescript
class SpendingPaused extends NoClickError
```

You paused this user's spending (`user.pauseSpending()`), so nothing that costs money runs for
them until `user.resumeSpending()`. `message` and `nextStep` are for you; `userMessage` and
`action` are what you asked NoClick to tell the user, to show them as they are; `since` is when
you paused them.

Error type `spending_paused`, HTTP 402.

| Attribute | Type | Description |
| --- | --- | --- |
| `userMessage` | `string | undefined` |  |
| `action` | `{ label: string; url: string } | undefined` |  |
| `since` | `Date | undefined` |  |

### SpendingPaused.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### SpendingPaused.errorType

```typescript
static errorType: string
```

## PermissionDenied

```typescript
class PermissionDenied extends NoClickError
```

The key or session lacks the scope, or the user it acts for can't do this (another user's object, a suspended user).

Error type `permission_denied`, HTTP 403.

### PermissionDenied.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### PermissionDenied.errorType

```typescript
static errorType: string
```

## PolicyDenied

```typescript
class PolicyDenied extends NoClickError
```

Your policy (`noclick.Policy`) forbids this tool.

Error type `policy_denied`, HTTP 403.

### PolicyDenied.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### PolicyDenied.errorType

```typescript
static errorType: string
```

## NotFound

```typescript
class NotFound extends NoClickError
```

Nothing by that id or name in this account, or owned by the user the call acts for.

Error type `not_found`, HTTP 404.

### NotFound.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### NotFound.errorType

```typescript
static errorType: string
```

## Conflict

```typescript
class Conflict extends NoClickError
```

It already exists (`existingId` names it), or another call holds it, like a conversation mid-turn. An edit of a
workflow's graph checked against a version it has moved on from (`ifVersion`) carries the workflow as it stands:
its `version` and `graph` (a `WorkflowGraph`), to decide again from.

Error type `conflict`, HTTP 409.

| Attribute | Type | Description |
| --- | --- | --- |
| `graph` | `WorkflowGraph | null` | The workflow's graph as it stands, on a refused edit of it (`null` on any other conflict). |
| `existingId` | `string | undefined` |  |
| `version` | `number | undefined` | The version kept, on a refused edit of a workflow's graph or of your channel sections. |

### Conflict.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### Conflict.errorType

```typescript
static errorType: string
```

## NotAvailable

```typescript
class NotAvailable extends NoClickError
```

Not available here: a feature the account doesn't have yet (phone numbers), or a sandbox that has stopped.

Error type `not_available`, HTTP 409.

### NotAvailable.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### NotAvailable.errorType

```typescript
static errorType: string
```

## ActionRequired

```typescript
class ActionRequired extends NoClickError
```

Something has to be set up first, such as an agent answering a number before it can place calls.

Error type `action_required`, HTTP 409.

### ActionRequired.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### ActionRequired.errorType

```typescript
static errorType: string
```

## AnswerRequired

```typescript
class AnswerRequired extends NoClickError
```

A workflow build waits on an answer, and `question` says what. Answer it with `build.answer(...)`
where `question.answerableFromCode`; otherwise send a person to `question.answerUrl`. Then
`build.wait()` again: it waits through a question it has thrown.

Error type `answer_required`.

| Attribute | Type | Description |
| --- | --- | --- |
| `question` | `BuildQuestion` |  |

### AnswerRequired.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### AnswerRequired.errorType

```typescript
static errorType: string
```

## NeedsConnection

```typescript
class NeedsConnection extends NoClickError
```

The connection has no account connected yet; send the person `connectUrl`.

Error type `needs_connection`, HTTP 424.

### NeedsConnection.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### NeedsConnection.errorType

```typescript
static errorType: string
```

## CredentialDisconnected

```typescript
class CredentialDisconnected extends NoClickError
```

The connection's account was revoked or stopped working; send the person `connectUrl` to reconnect it.

Error type `credential_disconnected`, HTTP 424.

### CredentialDisconnected.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### CredentialDisconnected.errorType

```typescript
static errorType: string
```

## QuotaExceeded

```typescript
class QuotaExceeded extends NoClickError
```

A spent quota: never retried automatically.

Error type `quota_exceeded`, HTTP 429.

### QuotaExceeded.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### QuotaExceeded.errorType

```typescript
static errorType: string
```

## PlanLimitReached

```typescript
class PlanLimitReached extends NoClickError
```

An agent's turn its model connection's Claude or ChatGPT plan turned down at its limit: `connection`, `window`, when
it's back (`resetsAt`) and what the agent did (`then`: it switched and carried on, waits until the reset, or asked
the owner to allow a paid key).

Error type `plan_limit_reached`, HTTP 429.

| Attribute | Type | Description |
| --- | --- | --- |
| `connection` | `string | undefined` |  |
| `window` | `string | undefined` |  |
| `resetsAt` | `string | undefined` |  |
| `then` | `Record<string, unknown> | undefined` |  |

### PlanLimitReached.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### PlanLimitReached.errorType

```typescript
static errorType: string
```

## RateLimited

```typescript
class RateLimited extends NoClickError
```

Too many requests, or a send cap reached (emails, inbox replies); `retry_after` says when to try again.

Error type `rate_limited`, HTTP 429.

### RateLimited.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### RateLimited.errorType

```typescript
static errorType: string
```

## UpstreamError

```typescript
class UpstreamError extends NoClickError
```

A service NoClick relays to refused the call or failed. A refusal, such as an integration's service
answering a run with an error, comes in its own words, its HTTP status in `details.upstream_status`,
and answers 424: it isn't retried, since sending the same call again won't help. A failure (a model's
provider down, a service that didn't answer) answers 503 and is retried; once retries run out,
retrying in a moment usually works. Where it matters, as for a database's statements, `applied` says
whether the call took effect:

    if (err instanceof UpstreamError && err.applied === false) await db.execute(sql, params);

Error type `upstream_error`, HTTP 503.

| Attribute | Type | Description |
| --- | --- | --- |
| `applied` | `boolean | null` | `false` when NoClick knows the call didn't take effect (a read, or a write the service never ran), so sending it again is safe; `true` when it did; `null` when NoClick can't tell, as for a write a database never answered (the message says so): check before sending it again. |
| `upstreamAttempts` | `number | undefined` | How many times NoClick sent the call to the service before giving up. |

### UpstreamError.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### UpstreamError.errorType

```typescript
static errorType: string
```

## RequestTimeout

```typescript
class RequestTimeout extends NoClickError
```

The work outlasted what one request may wait (about 90 seconds); it answers 503. Never retried
automatically, since the work may still be going on: an agent's turn goes on and lands in its
conversation (`details.operation_id` and `details.conversation` say where).

Error type `request_timeout`, HTTP 503.

### RequestTimeout.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### RequestTimeout.errorType

```typescript
static errorType: string
```

## ServerError

```typescript
class ServerError extends NoClickError
```

A 5xx the server could not describe as a platform error.

Error type `server_error`.

### ServerError.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### ServerError.errorType

```typescript
static errorType: string
```

## APIConnectionError

```typescript
class APIConnectionError extends NoClickError
```

The API could not be reached, even after retries.

Error type `connection_error`.

### APIConnectionError.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### APIConnectionError.errorType

```typescript
static errorType: string
```

## OperationFailed

```typescript
class OperationFailed extends NoClickError
```

An operation finished `failed` without a more specific error type.

Error type `operation_failed`.

### OperationFailed.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### OperationFailed.errorType

```typescript
static errorType: string
```

## OperationCanceled

```typescript
class OperationCanceled extends NoClickError
```

The operation was canceled before it finished.

Error type `operation_canceled`.

### OperationCanceled.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### OperationCanceled.errorType

```typescript
static errorType: string
```

## Expired

```typescript
class Expired extends NoClickError
```

A request, link or operation expired before anyone acted on it.

Error type `expired`, HTTP 410.

### Expired.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### Expired.errorType

```typescript
static errorType: string
```

## OperationTimeout

```typescript
class OperationTimeout extends NoClickError
```

`operation.wait({ timeoutS })` ran out before the operation finished.

Error type `operation_timeout`.

### OperationTimeout.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### OperationTimeout.errorType

```typescript
static errorType: string
```

## WebhookSignatureError

```typescript
class WebhookSignatureError extends NoClickError
```

A webhook delivery's `NoClick-Signature` doesn't match its body, or its timestamp is too old.
Thrown by `Webhook.verify` in your receiver; answer it with a 400 and drop the delivery.

Error type `webhook_signature_invalid`.

### WebhookSignatureError.retryAfter

```typescript
retryAfter: number | undefined
```

Seconds the server asked us to wait (from `Retry-After`), when it did.

### WebhookSignatureError.errorType

```typescript
static errorType: string
```

## OperationExpired

Another name for `Expired`.
