Gathering detailed insights and metrics for retry-axios
Gathering detailed insights and metrics for retry-axios
Gathering detailed insights and metrics for retry-axios
Gathering detailed insights and metrics for retry-axios
🦖 A super flexible interceptor for Axios that makes it easy to retry requests.
npm install retry-axios
Typescript
Module System
Min. Node Version
Node Version
NPM Version
97.9
Supply Chain
99
Quality
75.3
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
200,929,340
Last Day
59,217
Last Week
990,390
Last Month
4,123,924
Last Year
38,120,706
Apache-2.0 License
496 Stars
180 Commits
65 Forks
9 Watchers
5 Branches
20 Contributors
Updated on Jun 16, 2025
Latest Version
3.1.3
Package Id
retry-axios@3.1.3
Unpacked Size
35.58 kB
Size
11.29 kB
File Count
6
NPM Version
10.2.4
Node Version
20.9.0
Published on
Nov 16, 2023
Cumulative downloads
Total Downloads
Last Day
3.1%
59,217
Compared to previous day
Last Week
-5%
990,390
Compared to previous week
Last Month
6.2%
4,123,924
Compared to previous month
Last Year
32.2%
38,120,706
Compared to previous year
1
Use Axios interceptors to automatically retry failed requests. Super flexible. Built in exponential backoff.
1npm install retry-axios
To use this library, import it alongside of axios
:
1// Just import rax and your favorite version of axios 2const rax = require('retry-axios'); 3const axios = require('axios');
Or, if you're using TypeScript / es modules:
1import * as rax from 'retry-axios'; 2import axios from 'axios';
You can attach to the global axios
object, and retry 3 times by default:
1const interceptorId = rax.attach(); 2const res = await axios('https://test.local');
Or you can create your own axios instance to make scoped requests:
1const myAxiosInstance = axios.create(); 2myAxiosInstance.defaults.raxConfig = { 3 instance: myAxiosInstance 4}; 5const interceptorId = rax.attach(myAxiosInstance); 6const res = await myAxiosInstance.get('https://test.local');
You have a lot of options...
1const interceptorId = rax.attach(); 2const res = await axios({ 3 url: 'https://test.local', 4 raxConfig: { 5 // Retry 3 times on requests that return a response (500, etc) before giving up. Defaults to 3. 6 retry: 3, 7 8 // Retry twice on errors that don't return a response (ENOTFOUND, ETIMEDOUT, etc). 9 // 'noResponseRetries' is limited by the 'retry' value. 10 noResponseRetries: 2, 11 12 // Milliseconds to delay at first. Defaults to 100. Only considered when backoffType is 'static' 13 retryDelay: 100, 14 15 // HTTP methods to automatically retry. Defaults to: 16 // ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT'] 17 httpMethodsToRetry: ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT'], 18 19 // The response status codes to retry. Supports a double 20 // array with a list of ranges. Defaults to: 21 // [[100, 199], [429, 429], [500, 599]] 22 statusCodesToRetry: [[100, 199], [429, 429], [500, 599]], 23 24 // If you are using a non static instance of Axios you need 25 // to pass that instance here (const ax = axios.create()) 26 instance: ax, 27 28 // You can set the backoff type. 29 // options are 'exponential' (default), 'static' or 'linear' 30 backoffType: 'exponential', 31 32 // You can detect when a retry is happening, and figure out how many 33 // retry attempts have been made 34 onRetryAttempt: err => { 35 const cfg = rax.getConfig(err); 36 console.log(`Retry attempt #${cfg.currentRetryAttempt}`); 37 } 38 } 39});
If the logic in onRetryAttempt requires to be asynchronous, you can return a promise, then retry will be executed only after the promise is resolved:
1const res = await axios({ 2 url: 'https://test.local', 3 raxConfig: { 4 onRetryAttempt: err => { 5 return new Promise((resolve, reject) => { 6 // call a custom asynchronous function 7 refreshToken(err, function(token, error) { 8 if (!error) { 9 window.localStorage.setItem('token', token); 10 resolve(); 11 } else { 12 reject(); 13 } 14 }); 15 }); 16 } 17 } 18});
Or if you want, you can just decide if it should retry or not:
1const res = await axios({ 2 url: 'https://test.local', 3 raxConfig: { 4 // Override the decision making process on if you should retry 5 shouldRetry: err => { 6 const cfg = rax.getConfig(err); 7 return true; 8 } 9 } 10});
If you want to add custom retry logic without duplicating too much of the built-in logic, rax.shouldRetryRequest
will tell you if a request would normally be retried:
1const res = await axios({ 2 url: 'https://test.local', 3 raxConfig: { 4 // Override the decision making process on if you should retry 5 shouldRetry: err => { 6 const cfg = rax.getConfig(err); 7 if (cfg.currentRetryAttempt >= cfg.retry) return false // ensure max retries is always respected 8 9 // Always retry this status text, regardless of code or request type 10 if (err.response.statusText.includes('Try again')) return true 11 12 // Handle the request based on your other config options, e.g. `statusCodesToRetry` 13 return rax.shouldRetryRequest(err) 14 } 15 } 16});
This library attaches an interceptor
to an axios instance you pass to the API. This way you get to choose which version of axios
you want to run, and you can compose many interceptors on the same request pipeline.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
Found 4/7 approved changesets -- score normalized to 5
Reason
8 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More