softonic/axios-retry

How to handle errors

Closed this issue · 2 comments

I've got code like this, where any network errors are meant to be caught:

  try {
    const response = await axios.request(config);
    if (response.status !== 200) {
      throw new Error(
        `Unexpected status tracking event to our server ${response.status}`
      );
    }
  } catch (err) {
    console.error(err);
  }

But it seems when using axios-retry, after some retries, an error is thrown and its unhandled.

Ideally I'd love if my catch statement caught the final error.

My config:

axiosRetry(axios, {
  retryDelay: axiosRetry.exponentialDelay,
  onRetry: (retryCount, err, config) => {
    console.warn(
      `Retrying axios request for ${config.url} ${retryCount}: ${err.message}`
    );
  },
});

Are you looking for the code in the catch block to be executed when an error occurs after retries, rather than entering the block where
response.status !== 200?

I think I misunderstood what was happening here, will close the issue! Thanks