A 404 error is not returned directly as res.status
in the axios
library but thrown in the catch as an error.
My question is now can I somehow query in the catch, which number the error has?
.catch(error => {
if(error.status === 404)
// do something
}
Or how can I use the axios library to query if it is a 404 error or not?
const handleLogin = () => {
axios.post('localhost:4000', {"email":`${email}`, "password":`${password}`})
.then(res => {
console.log(res);
console.log(res.data);
console.log(res.status);
if(res.status === 200) {
setValidationNoExist(true);
history.push({
pathname: '/app',
state: {
email: email,
name: password,
},
})
}
else if(res.status === 203) {
setValidationWrong(false);
}
else if(res.status === 404) {
setValidationPending(false);
}
else if(res.status === 204) {
setValidationNoExist(false);
}
})
.catch(error => {
console.log(error)
setValidationNoExist(false);
})
};