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.

Axios not failing on chrome "canceled request".

See original GitHub issue

Summary

Google Chrome may cancel requests sometimes. Axios does not seem to throw an error when this happens.

Context

  • axios version: 0.17.1
  • Environment: Electron / Chrome / Chromium

For more details about what can cause this situation, here is a stackoverflow link "What does status=canceled for a resource mean in Chrome Developer Tools? ". This is also valid in Chromium (Electron apps).

I was expecting axios to fail and throw an error when this happens. But this code does not work:

refreshData () {
  this.isFetching = true
  this.fetchingError = false

  return this.fetchData()
    .then(() => {
      this.set('lastUpdated', new Date())
    })
    .catch((err) => {
      this.set('fetchingError', true)
    })
    .finally(() => {
      this.set('isFetching', false)
    })
}

Nor catch, nor finally run.

Is this an expected behaviour?

(In case you don’t know about: finally)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:24

github_iconTop GitHub Comments

4reactions
romankononovichcommented, May 27, 2020

it helped me -> event.preventDefault();

4reactions
juanr2001commented, Jun 14, 2018

Found the solution guys! @AoDev

Axios documentation has a timeout of 1000 like: axios.create({ ..., timeout: 1000, ... })

I increased the timeout to 5000. I think Axios documentation needs to be updated to change the timeout to a higher number to prevent newcomers to go crazy trying to figure out what’s going on.

I hope this solutions helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to catch status = cancelled in axios? - Stack Overflow
This happens because you set the timeout in axios. Of course when the request times out, axios cancels the request. By default timeout...
Read more >
Axios ajax call not working working on chrome but working safari
i'm struggling with this issue since a couple of hours now, on my app i'm requesting data from DB using axios ajax function....
Read more >
HTTP status and error codes for JSON | Cloud Storage
The resumable upload was cancelled at the client's request prior to completion. This error has no response body. 500—Internal Server Error. Reason, Description ......
Read more >
Cancel all axios requests in React's componentWillUnmount ...
The single action of cancelling API request when it is no longer needed ... React alerts us to this problem by outputting these...
Read more >
axios - npm
Requests can be made by passing the relevant config to axios . ... or to cancel the request by throwing an error //...
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