retry-axios

  • Version 4.0.0
  • Published
  • 56.6 kB
  • No dependencies
  • Apache-2.0 license

Install

npm i retry-axios
yarn add retry-axios
pnpm add retry-axios

Overview

Retry HTTP requests with Axios.

Index

Functions

function attach

attach: (instance?: AxiosInstance) => number;
  • Attach the interceptor to the Axios instance.

    Parameter instance

    The optional Axios instance on which to attach the interceptor.

    Returns

    The id of the interceptor attached to the axios instance.

function detach

detach: (interceptorId: number, instance?: AxiosInstance) => void;
  • Eject the Axios interceptor that is providing retry capabilities.

    Parameter interceptorId

    The interceptorId provided in the config.

    Parameter instance

    The axios instance using this interceptor.

function getConfig

getConfig: (error: AxiosError) => RetryConfig | undefined;
  • Acquire the raxConfig object from an AxiosError if available.

    Parameter err

    The Axios error with a config object.

function shouldRetryRequest

shouldRetryRequest: (error: AxiosError) => boolean;
  • Determine based on config if we should retry the request.

    Parameter err

    The AxiosError passed to the interceptor.

Interfaces

interface RetryConfig

interface RetryConfig {}
  • Configuration for the Axios request method.

property backoffType

backoffType?: 'linear' | 'static' | 'exponential';
  • Backoff Type; 'linear', 'static' or 'exponential'.

property checkRetryAfter

checkRetryAfter?: boolean;
  • Whether to check for 'Retry-After' header in response and use value as delay. Defaults to true.

property currentRetryAttempt

currentRetryAttempt?: number;
  • The number of retries already attempted.

property errors

errors?: AxiosError[];
  • Array of all errors encountered during retry attempts. Populated automatically when retries are performed. The first element is the initial error, subsequent elements are retry errors.

property httpMethodsToRetry

httpMethodsToRetry?: string[];
  • The HTTP Methods that will be automatically retried. Defaults to ['GET','PUT','HEAD','OPTIONS','DELETE']

property jitter

jitter?: 'none' | 'full' | 'equal';
  • Jitter strategy for exponential backoff. Defaults to 'none'. - 'none': No jitter (default) - 'full': Random delay between 0 and calculated exponential backoff - 'equal': Half fixed delay, half random

    Jitter helps prevent the "thundering herd" problem where many clients retry at the same time. Only applies when backoffType is 'exponential'.

property maxRetryAfter

maxRetryAfter?: number;
  • Max permitted Retry-After value (in ms) - rejects if greater. Defaults to 5 mins.

property maxRetryDelay

maxRetryDelay?: number;
  • Ceiling for calculated delay (in ms) - delay will not exceed this value.

property onError

onError?: (error: AxiosError) => void | Promise<void>;
  • Function to invoke when error occurred.

property onRetryAttempt

onRetryAttempt?: (error: AxiosError) => Promise<void>;
  • Function to invoke when a retry attempt is made. The retry will wait for the returned promise to resolve before proceeding. If the promise rejects, the retry will be aborted and the rejection will be propagated.

property retriesRemaining

retriesRemaining?: number;
  • The number of retries remaining before giving up. Calculated as: retry - currentRetryAttempt

property retry

retry?: number;
  • The number of times to retry the request. Defaults to 3.

property retryDelay

retryDelay?: number;
  • The delay in milliseconds used for retry backoff. Defaults to 100. - For 'static' backoff: Fixed delay between retries - For 'exponential' backoff: Base multiplier for exponential calculation - For 'linear' backoff: Ignored (uses attempt * 1000)

property shouldRetry

shouldRetry?: (error: AxiosError) => boolean;
  • Function to invoke which determines if you should retry. This is called after checking the retry count limit but before other default checks. Return true to retry, false to stop retrying. If not provided, uses the default retry logic based on status codes and HTTP methods.

property statusCodesToRetry

statusCodesToRetry?: number[][];
  • The HTTP response status codes that will automatically be retried. Defaults to: [[100, 199], [429, 429], [500, 599]]

Type Aliases

type RaxConfig

type RaxConfig = {
raxConfig: RetryConfig;
} & AxiosRequestConfig;

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (12)

    Peer Dependencies (1)

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/retry-axios.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/retry-axios)
    • HTML
      <a href="https://www.jsdocs.io/package/retry-axios"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>