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 returns a generic "Network Error" even when the request got a response code

See original GitHub issue

Describe 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)
    });

image image

My axios instance code: https://github.com/Miodec/monkeytype/blob/master/src/js/axios-instance.js

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:34

github_iconTop GitHub Comments

11reactions
lincolnzera1commented, Sep 24, 2022

In my case, the CORS was blocking the frontend from acessing the backend. My Solution: Add this in the server-side:

                 Using npm, install 'cors':
                  npm i cors
                  
                  And add this lines to the code:

                  let cors = require("cors");
                  app.use(cors());
5reactions
orengatignocommented, Apr 26, 2022

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)

image
Read more comments on GitHub >

github_iconTop 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 >

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