2

Im trying to catch validation errors from the server.

Code:

axios.post('https://myBackendIp.com/api/teacher/time/create',Data)
.then(res=>{
       console.log(res)
 }).catch(error=>{
       console.log(error)
 })

Console log output

Error: Network Error
at createError (createError.js:16)
at handleError (xhr.js:87)

Network tab output

{"error":{"message":"Check your date field","status_code":500}}

Is there a way to change that or I'm doing something wrong?

Thanks!

1
  • i can't understand your question..? you are always handling async call exception right Commented May 21, 2019 at 10:43

1 Answer 1

5

After Googling a little, I found this ticket:

https://github.com/axios/axios/issues/960

It recommends using:

console.log(error.response)

instead of

console.log(error)

Edit 1:

Did some further reading, apparently this could be a symptom of a CORS issue, see this and this.

The request on the network tab might seem like it's succeeding, however, when it's processed by Axios, a Network Error is returned.

Sign up to request clarification or add additional context in comments.

5 Comments

i cant get any solving methods from that tickets
Alright - what happens to your output when you use the code above?
i saw the "undefined" message in log when i use console.log(error.response)
@SanjeevanRaja - I added an additional answer above, maybe investigate that?
Yes. you are correct @n15m0-jk. I solved my problem. its a CORS issue. Thank you so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.