I have a use case where i need to retry Axios POST requests in case of API timeout while trying to POST the request. I need to retry 3 times in case of API timeout and each retry request should timeout in 4 secs if the POST operation cant be pleted in that period. I am using the below code but neither the retry or the timeout seems to work. Could you let me know what is wrong and the correct code snippet for this?
axiosRetry(axios, { retries: 3 });
axios.post(url,payload,{headers:header},{timeout:4000})
I have a use case where i need to retry Axios POST requests in case of API timeout while trying to POST the request. I need to retry 3 times in case of API timeout and each retry request should timeout in 4 secs if the POST operation cant be pleted in that period. I am using the below code but neither the retry or the timeout seems to work. Could you let me know what is wrong and the correct code snippet for this?
axiosRetry(axios, { retries: 3 });
axios.post(url,payload,{headers:header},{timeout:4000})
Share
Improve this question
asked Jan 27, 2020 at 0:46
vignesh dvignesh d
3053 gold badges9 silver badges16 bronze badges
2
- 1 POST requires enabling specifically. By default only idempotent calls are retried (i.e. GETs) – Dean Commented Mar 24, 2021 at 17:07
- @Dean do you have a link to this documentation? I've been looking for this answer for a while. – Peter Davis Commented Jan 30, 2023 at 15:21
1 Answer
Reset to default 4retry-axios has its own named configuration, and the retry delay can be setup at top level i.e.
const res = await axios({
url,
method: 'post',
data: payload,
raxConfig: {
retry: 3,
retryDelay: 4000
}
});