Socket
Socket
Sign inDemoInstall

axios-retry-after

Package Overview
Dependencies
9
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    axios-retry-after

A tiny HTTP 429 Retry-After interceptor for axios


Version published
Weekly downloads
7.6K
decreased by-6.83%
Maintainers
1
Install size
5.48 kB
Created
Weekly downloads
 

Changelog

Source

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

Readme

Source

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)
  }
}))

Keywords

FAQs

Last updated on 05 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc