question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intercept timeout errors?

See original GitHub issue

I use interceptors.response.use to log details about the for every request we do (error or success). It’s very useful to have it in our logs to investigate on issues. But when we get a timeout error, those interceptors are not invoked so all we get in our logs is:Error: timeout of 3000ms exceeded Is there some kind of global event or something that I could use to add context to timeout errors?

Context

  • axios version: v0.16.2
  • Environment: node v8.5.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:6

github_iconTop GitHub Comments

31reactions
nickknissencommented, Dec 5, 2018

When a timeout happens it will return an error code with the value ECONNABORTED https://github.com/axios/axios/blob/b7d8d126dad7341addcd7b063f7b261955ec9152/lib/adapters/xhr.js#L95

This is more or less how i do it:

axios.interceptors.response.use(
  config => config,
  (error) => {
    if (error.response.status === 408 || error.code === 'ECONNABORTED') {
      console.log(`A timeout happend on url ${error.config.url}`)
    }
    return Promise.reject(error);
  },
);
1reaction
davidlukericecommented, Dec 5, 2018

The ECONNABORTED code is also used when the request is manually aborted: https://github.com/axios/axios/blob/503418718f669fcc674719fd862b355605d7b41f/lib/adapters/xhr.js#L71 Is there a good way to differentiate between the server request timeouts and manual aborts?

We’re not currently using .abort() anywhere, so that check works for us for now, but I could see a bug crop up if we later had to add in a manual request cancel and forgot about our assumption of using that code only for the timeout case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress and Flaky Tests: How to Handle Timeout Errors
Flaky Cypress Tests Caused by Timeout Errors ... To accomplish this, start by defining the intercepted route and assigning it an alias.
Read more >
Demonstrate a timeout and error HTTP interceptor. - StackBlitz
Demonstrate a timeout and error HTTP interceptor.
Read more >
cypress - How to match intercept on response - Stack Overflow
So the test is failing because status is Running, and the expected is Completed. how to increase timeout in this case? cy.intercept('GET', ...
Read more >
intercept - Cypress Documentation
Spy and stub network requests and responses. Tip: We recommend you read the Network Requests guide first. All intercepts are automatically cleared before....
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
Imagine you are trying to check how your application handles a network communication error. Internet is unreliable, servers go down and come ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found