最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

laravel - Axios catch error returns JavaScript error not server response - Stack Overflow

programmeradmin0浏览0评论

Im trying to catch validation errors from the server.

Code:

axios.post('',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!

Im trying to catch validation errors from the server.

Code:

axios.post('https://myBackendIp./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!

Share Improve this question asked May 21, 2019 at 10:41 Sanjeevan RajakulasingamSanjeevan Rajakulasingam 511 silver badge8 bronze badges 1
  • i can't understand your question..? you are always handling async call exception right – Hamit YILDIRIM Commented May 21, 2019 at 10:43
Add a ment  | 

1 Answer 1

Reset to default 5

After Googling a little, I found this ticket:

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

It remends 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.

发布评论

评论列表(0)

  1. 暂无评论