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

# Class: RetryInterceptor

> RetryInterceptor class in the Terminal49 TypeScript SDK, automatically retrying failed requests on rate-limit and server errors with exponential backoff.

# Class: RetryInterceptor

Retries transient failures with backoff. Two kinds of failure are handled:

* A response with a retryable status (429 / 5xx), handled in `onResponse`.
* A thrown transport error (DNS/connection/"fetch failed"), handled in
  `onError` — these never reach `onResponse` because `fetch` rejected.

Retries are gated by shouldRetryRequest: idempotent methods are always
eligible, but non-idempotent writes are only retried when the caller supplied
an `Idempotency-Key` header. 429 backoff honors the server's `Retry-After`.

## Constructors

### Constructor

> **new RetryInterceptor**(`maxRetries`, `fetchImpl?`): `RetryInterceptor`

#### Parameters

| Parameter    | Type                                         | Default value |
| ------------ | -------------------------------------------- | ------------- |
| `maxRetries` | `number`                                     | `undefined`   |
| `fetchImpl`  | (`input`, `init?`) => `Promise`\<`Response`> | `fetch`       |

#### Returns

`RetryInterceptor`

## Methods

### onError()

> **onError**(`__namedParameters`): `Promise`\<`Error` | `Response`>

Recover from a thrown transport error by retrying eligible requests. If a
retry produces a response we return it (openapi-fetch then runs the normal
`onResponse` chain on it); otherwise we surface a normalized
NetworkError so error mapping is consistent with the response path.

#### Parameters

| Parameter           | Type                                                                  |
| ------------------- | --------------------------------------------------------------------- |
| `__namedParameters` | `Pick`\<`MiddlewareCallbackParams`, `"id"` \| `"request"`> & `object` |

#### Returns

`Promise`\<`Error` | `Response`>

***

### onRequest()

> **onRequest**(`__namedParameters`): `Request`

#### Parameters

| Parameter           | Type                                                       |
| ------------------- | ---------------------------------------------------------- |
| `__namedParameters` | `Pick`\<`MiddlewareCallbackParams`, `"id"` \| `"request"`> |

#### Returns

`Request`

***

### onResponse()

> **onResponse**(`__namedParameters`): `Promise`\<`Response`>

#### Parameters

| Parameter           | Type                                                                  |
| ------------------- | --------------------------------------------------------------------- |
| `__namedParameters` | `Pick`\<`MiddlewareCallbackParams`, `"id"` \| `"request"`> & `object` |

#### Returns

`Promise`\<`Response`>
