axios-retry is set up, but failed requests are not retried
Fix it fast
Most common cause, 1 of 4The default condition skips POST answers and other status codes
Write your own retryCondition that names exactly what may repeat.
import axios from 'axios';
import axiosRetry, { isNetworkOrIdempotentRequestError } from 'axios-retry';
const client = axios.create({ baseURL: 'https://api.example.com' });
axiosRetry(client, {
retries: 3,
// POST is added here only because this API ignores repeated job requests
retryCondition: (error) =>
isNetworkOrIdempotentRequestError(error) ||
(error.config?.method === 'post' && error.response?.status === 503),
});Short answer
axios-retry 4.5 retries only what retryCondition approves: by default a network error without a response, or a 429 or 5xx answer to GET, HEAD, OPTIONS, PUT or DELETE. POST answers and ECONNABORTED timeouts are skipped, retries have no delay, and only the axios instance passed to axiosRetry is covered. Set retryCondition, retryDelay and shouldResetTimeout to match.
Which cause do you have?
Add an onRetry hook that logs each attempt with its method, URL and reason. No log at all means the retry condition rejected the error or the hook sits on another instance; a burst of logs in the same millisecond means there is no delay.
axiosRetry(client, {
retries: 3,
onRetry: (retryCount, error, requestConfig) => {
console.log(Date.now(), 'retry', retryCount, requestConfig.method, requestConfig.url,
error.code ?? error.response?.status);
},
});Then find the line you see in this list and open its fix:
- 1The default condition skips POST answers and other status codes
onRetry stays silent for POST or PATCH requests that got a 5xx, and for 4xx answers other than 429 - 2Timeouts are excluded, and every attempt shares one timeout
The error code is ECONNABORTED, the code axios gives its own timeouts by default, and no retry follows - 3There is no delay, so all retries hit the same outage
The onRetry timestamps are a few milliseconds apart, and a server that needs a second to recover fails every attempt - 4axiosRetry was attached to a different instance, or not called at all
Retries work for axios.get() but never for a client made with axios.create(), or the setup line throws in CommonJS
What does the error look like?
A POST that gets a 503 fails at once and onRetry is never calledA request that hits the axios timeout fails with ECONNABORTED and is not retriedAll retry attempts land within a few milliseconds of each otherCalling axiosRetry in CommonJS throws a TypeError that it is not a function
Cause 1 of 4
The default condition skips POST answers and other status codes
You seeonRetry stays silent for POST or PATCH requests that got a 5xx, and for 4xx answers other than 429
Check
axios-retry does not retry a POST that got a 5xx because the default retryCondition only retries responses to idempotent methods. That default, isNetworkOrIdempotentRequestError, retries a network error that has no response for any method, but retries a 429 or 5xx response only for GET, HEAD, OPTIONS, PUT and DELETE.
grep -rn "retryCondition" src/Fix
Write your own retryCondition that names exactly what may repeat. Add POST only for endpoints where sending the same request twice cannot create duplicate records.
import axios from 'axios';
import axiosRetry, { isNetworkOrIdempotentRequestError } from 'axios-retry';
const client = axios.create({ baseURL: 'https://api.example.com' });
axiosRetry(client, {
retries: 3,
// POST is added here only because this API ignores repeated job requests
retryCondition: (error) =>
isNetworkOrIdempotentRequestError(error) ||
(error.config?.method === 'post' && error.response?.status === 503),
});Verify
Send a POST to a throwaway local server that always answers 503; onRetry logs three attempts before the error reaches your code.
import http from 'node:http';
const server = http.createServer((req, res) => { res.statusCode = 503; res.end(); }).listen(4010);
await client.post('http://127.0.0.1:4010/jobs', {}).catch((e) => console.log('final', e.response?.status));
server.close();Confirmed by github.com
Cause 2 of 4
Timeouts are excluded, and every attempt shares one timeout
You seeThe error code is ECONNABORTED, the code axios gives its own timeouts by default, and no retry follows
Check
axios-retry does not retry an axios timeout because its built-in checks drop errors with the code ECONNABORTED, which axios uses for its own timeout unless transitional.clarifyTimeoutError is on. With shouldResetTimeout left at false, later attempts also get only what is left of the first timeout, and none run once it is used up.
grep -rnE "timeout:|shouldResetTimeout|clarifyTimeoutError" src/Fix
If timed-out requests are safe to repeat, accept ECONNABORTED in retryCondition and set shouldResetTimeout so each attempt gets the full timeout again.
axiosRetry(client, {
retries: 3,
shouldResetTimeout: true,
retryCondition: (error) =>
isNetworkOrIdempotentRequestError(error) ||
(error.code === 'ECONNABORTED' &&
['get', 'head', 'options'].includes(error.config?.method)),
});Verify
Aim a GET with a short timeout at a local server that never answers; onRetry now logs each attempt with ECONNABORTED.
import http from 'node:http';
const server = http.createServer(() => {}).listen(4011);
await client.get('http://127.0.0.1:4011/', { timeout: 500 }).catch((e) => console.log('final', e.code));
server.close();Confirmed by github.com
Cause 3 of 4
There is no delay, so all retries hit the same outage
You seeThe onRetry timestamps are a few milliseconds apart, and a server that needs a second to recover fails every attempt
Check
axios-retry looks broken when every attempt fires at once and fails against the same outage, because the default retryDelay is zero. It waits only when the response carries a Retry-After header; otherwise it returns 0 and the next attempt starts at once.
grep -rn "retryDelay" src/Fix
Use the bundled exponential back-off. It doubles the wait on each attempt, adds a little random jitter and still honours Retry-After when that is longer.
axiosRetry(client, {
retries: 4,
retryDelay: (retryCount, error) => axiosRetry.exponentialDelay(retryCount, error, 500),
});Verify
Against a local server that always answers 503, the onRetry timestamps for a GET now grow apart by roughly one, two and four seconds.
await client.get('http://127.0.0.1:4010/').catch((e) => console.log('final', e.response?.status));Confirmed by github.com
Cause 4 of 4
axiosRetry was attached to a different instance, or not called at all
You seeRetries work for axios.get() but never for a client made with axios.create(), or the setup line throws in CommonJS
Check
axios-retry never runs for a client when axiosRetry was attached to a different axios instance, or when CommonJS code called the module object instead of its default export. axiosRetry adds its interceptors to the one instance you pass it, and every instance from axios.create() starts with empty interceptor lists of its own. In CommonJS the function sits on the default export, so a plain require() returns the module object, not the function.
grep -rnE "axios\.create|axiosRetry\(" src/
node -e "console.log(typeof require('axios-retry'), typeof require('axios-retry').default)"Fix
Pass every client you actually use to axiosRetry, and in CommonJS take the default export.
const axios = require('axios');
const axiosRetry = require('axios-retry').default;
const client = axios.create({ baseURL: 'https://api.example.com' });
axiosRetry(client, { retries: 3 });Verify
With the onRetry hook from the first step on the same client, a failing GET through it now logs its attempts.
client.get('http://127.0.0.1:4010/').catch((e) => console.log('final', e.response?.status));Confirmed by github.com
How do I stop it coming back?
- Keep one module that creates the axios client and applies axiosRetry, and import that client everywhere.
- Decide per endpoint whether a repeat is safe before you widen retryCondition.
- Always set retryDelay; instant retries add load to a server that is already struggling.
- The axios-retry repository is archived; the README says the 4.5.0 release stays on npm and keeps working, so pin that version.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.