interface RetryOptions {
    maxRetries?: number;
    onError?: (err: unknown, request: Request) => boolean;
    onResponse?: (response: Response, request: Request) => boolean;
    onRetry?: (attempt: number, request: Request) => void | Request;
    retryDelay?: number | (retryCount: number) => number;
    returnLastResponse?: boolean;
    skip?: (request: Request) => boolean;
}

Properties

maxRetries?: number

max number of retries

5
onError?: (err: unknown, request: Request) => boolean

function that will be called if an error is thrown while calling the rest of the middleware chain, and should return whether the error should be retried

() => true

onResponse?: (response: Response, request: Request) => boolean

function that will be called whenever a response is received, and should return whether the response is valid (i.e. should be returned and not retried)

response => response.status < 500

onRetry?: (attempt: number, request: Request) => void | Request

function that will be called before a retry is attempted, and can be used to modify the request before proceeding

Type declaration

    • (attempt: number, request: Request): void | Request
    • Parameters

      • attempt: number

        current retry attempt (starts at 0)

      • request: Request

      Returns void | Request

retryDelay?: number | (retryCount: number) => number

delay between retries

retryCount * 1000, up to 5000
returnLastResponse?: boolean

if true, the last response will be returned if the number of retries is exceeded instead of throwing RetriesExceededError

false
skip?: (request: Request) => boolean

function that will be called before starting the retry loop. if it returns false, the retry loop will be skipped and the error will be thrown immediately

() => false