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 returning response for POST on 500 error

See original GitHub issue

I setup a basic demo, where I create a POST request and server returns 500 error. With postman I get response, but axios doesn’t return response. https://jsfiddle.net/8r3dh6hw/61/

Response from Postman: 500 Internal Server Error

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:11

github_iconTop GitHub Comments

36reactions
guaranicommented, Oct 30, 2017

@themre For me, what worked was to implement validateStatus and return true for the status codes I wanted to handle in the then callback.

    axios({
      method: 'post',
      url: '/sessions',
      data: {
        username: this.state.username,
        password: this.state.password,
      },
      validateStatus: (status) => {
        return true; // I'm always returning true, you may want to do it depending on the status received
      },
    }).catch(error => {

    }).then(response => {
        // this is now called!
    });
11reactions
raygesualdocommented, Jan 8, 2018

@themre In your jsfiddle, if you look in the browser dev tools, you’ll notice that the call to httpstat.us/500 errors during the OPTIONS pre-flight request (an automated network call in modern browsers when using CORS). When making a cross-domain request, if the server isn’t correctly configured for CORS, axios returns an error without error.response populated. This is because the XHR request fails at the browser level (during the OPTIONS call), which is technically a network error. For network errors, axios does not provide a response because one is not provided by the browser. If one debugs the network error returned to axios from an invalid OPTIONS call, one will notice that there is no way to know the status.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Axios POST request fails with error status code 500
Most of the time it happens because of using wrong content type header. Open postman and see "Body" ...
Read more >
500 (Internal Server Error) when POSTing to controller with ...
Hi! I'm making an Instagram 'clone' and want to add comments using Axios. I have a resourceful controller setup and a Vue instance...
Read more >
trying to post json with axios? 500 (Internal Server Error)?
I'm trying to convert the plain text that's entered from review with axios. However I get an error in the console log saying:...
Read more >
request failed with status code 500 axios post - You.com
While it seems like that there are quite a few reasons you might get a 500 response from an Axios call, my case...
Read more >
Axios HTTP error handling in Express.js
A status code 5xx indicates an error at the other service or in the network between our and the other service. Some of...
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