Axios returns a generic "Network Error" even when the request got a response code
See original GitHub issueDescribe the bug
When making a request to my API, the catch block has a generic “Network Error” message, but when checking in the network inspector the request got a response code 413. This causes my users to incorrectly report that ‘the website thinks i dont have a solid internet connection’. I suspect this happens for other codes too because this has been going on for a while.
To Reproduce
Make a request with a very large payload to trigger a 413 response
Expected behavior
The catch block should have the response code
Environment
- Axios Version: 0.25.0 and 0.21.2
- Adapter: xhr (i think? i dont remember changing this, so i guess whatever is default?)
- Browser: Chrome
- Browser Version: 97.0.4692.99
- Node.js Version: 14.18.1
- OS: OSX 12.1
Additional context/Screenshots
axiosInstance
.post("/results/add", {
result: completedEvent, //this is very big
})
.then((response) => {
// handle response
})
.catch((e) => {
console.log(e);
//this console logs Error: Network Error
// at createError (monkeytype.js:formatted:35086:25)
// at XMLHttpRequest.handleError (monkeytype.js:formatted:34457:28)
});
My axios instance code: https://github.com/Miodec/monkeytype/blob/master/src/js/axios-instance.js
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:34
Top Results From Across the Web
javascript - React: Axios Network Error
I received a network error with axios 0.27.2 when I was trying to upload an image to our server. After I set headers...
Read more >How to fix Axioserror: Network error?
This is a generic network error in Axios that can be triggered even when your API responds with a status code. There are...
Read more >Axios Network Error when making HTTP request [Solved]
Make sure that the URL you're passing to axios is correct #. Make sure that the URL you've specified when making the HTTP...
Read more >Handling Errors With Axios
This error is most commonly caused by a bad/spotty network, a hanging backend that does not respond instantly to each request, unauthorized or ......
Read more >Handling Errors | Axios Docs
axios.get('/user/12345') .catch(function (error) { if (error.response) { // The request was made and the server responded with a status code // that falls ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In my case, the CORS was blocking the frontend from acessing the backend. My Solution: Add this in the server-side:
it’s CORS problem, once you resolve the CORS issue (for example install CORS Unblock extension plug in Chrome) it will retrieve the response code (for me it was 504)