vignesh d
vignesh d

Reputation: 305

axios retry with timeout

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

Answers (1)

James
James

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

Related Questions