8๐
โ
You must use response
property or error
object:
handleSubmit () {
this.$http.post('http://localhost:3000/users/create', this.user)
.then(response => {
// if on server side you use only status 200, here it's always true
if (response.status=== 200) {
router.push('/users');
}
})
.catch(error => {
// error.response can be null
if (error.response && error.response.status === 400) {
console.log(error.response.data.error);
}
})
}
See documentation of axios error handling
๐คAlex
0๐
Try send instead of json? Also perhaps accessing error.
BACKEND
res.status(400).send({ error: 'Email already exists!' })
FRONTEND
(err) => { console.log(err["error"]) }
๐คMichael Paccione
Source:stackexchange.com