Reputation: 305
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 completed 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})
Upvotes: 7
Views: 17302
Reputation: 82136
retry-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
}
});
Upvotes: 4