How to catch the server response, even if 400 bad request error occured?
you need to log the data of the response:
axios.post('http://localhost/users', this.state)
.then(function(response) {
browserHistory.push('/features');
})
.catch(function(error) {
console.log(error.response.data); // this is the part you need that catches 400 request
});
Just looking at the axios documentation, it looks like the response should be exposed in the error object (i.e. console.log(error.response)
).
More information about different info provided when the response code falls out of 2xx here: https://github.com/mzabriskie/axios#handling-errors