Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

axios-retry-after

compwright2.8kMIT2.1.0

A tiny HTTP 429 Retry-After interceptor for axios

axios, retry, retry-after, api, rest

readme

axios-retry-after

Build Status Download Status Sponsor on GitHub

A tiny HTTP retry interceptor for axios.

This interceptor catches HTTP 429 errors, reads the Retry-After header, and retries the request at the proper type.

Installation

With NPM:

npm install --save axios-retry-after

With Yarn:

yarn add axios-retry-after

Example usage

import axios from 'axios'
import retry from 'axios-retry-after'
const client = axios.createClient()
client.interceptors.response.use(null, retry(client))

Customizing retry behavior

You can optionally customize the behavior of this interceptor by passing a second argument including one or more of the methods demonstrated below:

client.interceptors.response.use(null, retry(client, {
  // Determine when we should attempt to retry
  isRetryable (error) {
    return (
      error.response && error.response.status === 429 &&
      // Use X-Retry-After rather than Retry-After, and cap retry delay at 60 seconds
      error.response.headers['x-retry-after'] && error.response.headers['x-retry-after'] <= 60
    )
  }

  // Customize the wait behavior
  wait (error) {
    return new Promise(
      // Use X-Retry-After rather than Retry-After 
      resolve => setTimeout(resolve, error.response.headers['x-retry-after'])
    )
  }

  // Customize the retry request itself
  retry (axios, error) {
    if (!error.config) {
      throw error
    }

    // Apply request customizations before retrying
    // ...

    return axios(error.config)
  }
}))

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.1.0 (2024-04-28)

Features

  • support seconds and dates in Retry-After header (a8c0828)

2.0.0 (2022-10-05)

⚠ BREAKING CHANGES

  • upgrade to axios v1.0.0
  • package: drop support for Node.js < 14
  • module: now an ES6 module

Features

  • module: now an ES6 module (7ce1787)
  • upgrade to axios v1.0.0 (56b8bfa)
  • package: drop support for Node.js < 14 (b0f2efe)

Changelog

v1.0.3 (2021-05-25)

Full Changelog

v1.0.2 (2021-01-12)

Full Changelog

v1.0.1 (2020-12-16)

Full Changelog

v1.0.0 (2020-07-20)

Full Changelog