How can i detect if the maximum axios-retry has been completed?

951 Views Asked by At

I'm using axios-retry to detec if there is no internet connection, once the axios request fails due to the network i have this running.

axiosRetry(axios, {
  retries: 5, // number of retries
  retryDelay: (retryCount) => {
    console.log(`retry attempt: ${retryCount}`);
    return retryCount * 5000; // time interval between retries
  },
  retryCondition: axiosRetry.isRetryableError
});

Is it possible to run handleLogout() (which logout the user); only if it reached the maximum retries of 5? and then stop retrying the others axios that would fail at the meantime?

1

There are 1 best solutions below

1
davidhu On

I believe that you can just catch the error which will only happen if retry attempt exceed the max.

for example,

axiosRetry(axios, {
  retries: 5, // number of retries
  retryDelay: (retryCount) => {
    console.log(`retry attempt: ${retryCount}`);
    return retryCount * 5000; // time interval between retries
  },
  retryCondition: axiosRetry.isRetryableError
});

axios.get('/users')
  .then(res => handleSuccess(res))
  .catch(err => handleError(err))