Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

axios-retry-after

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-retry-after

A tiny HTTP 429 Retry-After interceptor for axios

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.3K
increased by34.69%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 28 Apr 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc