I am having a axios request in my react application, for which I am following the axios npm docs.
This is my axios request
axios.post(helper.getLoginApi(), data)
.then((response) => {
console.log(response);
this.props.history.push(from.pathname)
})
.catch((error)=> {
console.log(error);
})
I am able to successfully log the data on a successful request. However When I intentionally produce an error and try to console.log it, I don't get the result logged instead, I just see
POST http://localhost:3000/login 401 (Unauthorized) :3000/login:1
Error: Request failed with status code 401 login.js:66at createError (createError.js:16)
at settle (settle.js:18)
at XMLHttpRequest.handleLoad (xhr.js:77)
However when I go to Network Tab in Chrome Console, I can see the below response returned.
Thanks for help in advance .
try {} catch(e) {}
statement? Have you tried checking theresponse.status
insidethen
? Just some ideas - I don't know why it won't work – lumioresponse.data
but not in the.catch
block – Jagrati2xx
. Have you tried throwing an error insidethen
whenresponse.status
is not 200? – lumio