Timeout feature in the axios library is not working

From this axios issue (Thanks to zhuyifan2013 for giving the solution), I’ve found that axios timeout is response timeout not connection timeout.

Let say you’ve requested the URL through axios and server is taking long time to respond, in this case the axios timeout will work.

But you don’t have internet connection or the IP address or domain name that you’re requesting not there, in this case axios timeout will not work.

You have to use one of the axios cancellation methods – cancelToken example:

const source = CancelToken.source();
const timeout = setTimeout(() => {
  source.cancel();
  // Timeout Logic
}, 10000);

axios.get(ip + '/config', {cancelToken: source.token}).then((result) => {
  // Clear The Timeout
  clearTimeout(timeout);

  // Handle your response
});

Please note that if you’ve valid connection, still the Timeout Logic block will get executed. So you’ve to clear the timeout.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)