K
K
korchuni2019-01-23 17:42:05
React
korchuni, 2019-01-23 17:42:05

How to catch 400 error from server in react on post request?

I work with api firebase, when authorizing, if the email is not correct, the server returns a 400 error with the error object with the message "INVALID_EMAIL"
5c487bb2337af085393849.jpeg
It turns out that the server issues a 400 error, I cannot access this object and get information about the error

axios.post(url, authData).then(response => console.log(response )).catch(error => console.log(error))

In catch I get the following error Error: Request failed with status code 400
at createError (createError.js:17)
at settle (settle.js:19)
at XMLHttpRequest.handleLoad (xhr.js:78)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Okhotnikov, 2019-01-23
@korchuni

Try to output in catch through
console.log(error.response)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question