---
url: https://haihv.github.io/valifetch/api/index/type-aliases/RetryOptions.md
---

# Type Alias: RetryOptions

> **RetryOptions** = `object`

Defined in: [src/types/options.ts:71](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/options.ts#L71)

Retry configuration. A per-request or child-instance `retry` value replaces
the instance `retry` object entirely (fields, including `maxRetryAfter`, are
not merged with the parent's); unset fields take the built-in defaults.

## Properties

### delay?

> `optional` **delay?**: (`attemptCount`) => `number`

Defined in: [src/types/options.ts:84](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/options.ts#L84)

Custom delay function returning the milliseconds to wait before the next
attempt. `attemptCount` is 0-based, so `delay(0)` precedes the first retry.

#### Parameters

##### attemptCount

`number`

#### Returns

`number`

#### Default

```ts
(attemptCount) => 0.3 * 2 ** attemptCount seconds, plus up to 20% jitter, capped at 30 s
```

***

### limit?

> `optional` **limit?**: `number`

Defined in: [src/types/options.ts:73](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/options.ts#L73)

Max retry attempts (default: 2)

***

### maxRetryAfter?

> `optional` **maxRetryAfter?**: `number`

Defined in: [src/types/options.ts:103](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/options.ts#L103)

Longest server-sent `Retry-After` delay, in milliseconds, the client is
willing to wait. When a retryable response asks for longer (integer seconds
or HTTP-date), the request is NOT retried: the response is handled as if
retries were exhausted (an `HTTP_ERROR` through `beforeError`, or returned
as-is with `throwHttpErrors: false`). The check runs after `shouldRetry`
says "retry" and before `beforeRetry`, so no `beforeRetry` hook or `retry`
debug event fires for it. `Infinity` honours any value (the wait itself is
still clamped to the ~24.8-day `setTimeout` limit); a non-number, `NaN` or
negative value falls back to the default. A malformed `Retry-After` (not
all-digit seconds, not an HTTP-date) is ignored in favour of `delay`.

A per-request or child-instance `retry` value replaces the instance `retry`
object entirely (fields are not merged), so restate `maxRetryAfter` there
if you changed it.

#### Default

```ts
60000
```

***

### methods?

> `optional` **methods?**: [`HttpMethod`](HttpMethod.md)\[]

Defined in: [src/types/options.ts:75](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/options.ts#L75)

Methods to retry (default: GET, PUT, HEAD, DELETE, OPTIONS)

***

### shouldRetry?

> `optional` **shouldRetry?**: (`context`) => `boolean` | `undefined` | `Promise`<`boolean` | `undefined`>

Defined in: [src/types/options.ts:112](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/options.ts#L112)

Custom retry predicate. Return `true` to retry even when `statusCodes`/`methods`
would not, `false` to never retry this failure, or `undefined` to defer to the
built-in status-code + method check. Always bounded by `limit`. Runs before
`beforeRetry` hooks and only for failed responses (`response.ok === false`)
or network errors. May be async (e.g. inspect `response.clone().json()`).
A throwing predicate aborts the request with that error.

#### Parameters

##### context

[`RetryContext`](RetryContext.md)

#### Returns

`boolean` | `undefined` | `Promise`<`boolean` | `undefined`>

***

### statusCodes?

> `optional` **statusCodes?**: `number`\[]

Defined in: [src/types/options.ts:77](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/options.ts#L77)

Status codes to retry (default: 408, 413, 429, 500, 502, 503, 504)
