我正在尝试从服务器捕获验证错误。
代码:
axios.post('https://myBackendIp.com/api/teacher/time/create',Data)
.then(res=>{
console.log(res)
}).catch(error=>{
console.log(error)
})
控制台日志输出
Error: Network Error
at createError (createError.js:16)
at handleError (xhr.js:87)
网络选项卡输出
{"error":{"message":"Check your date field","status_code":500}}
有办法改变它还是我做错了什么?
谢谢!
最佳答案
谷歌搜索了一下后,我找到了这张票:
https://github.com/axios/axios/issues/960
建议使用:
console.log(error.response)
而不是
console.log(error)
编辑 1:
做了一些进一步的阅读,显然这可能是 CORS 问题的症状,请参阅 this和 this .
网络选项卡上的请求看似成功,但是,当 Axios 处理该请求时,会返回网络错误
。
关于javascript - Axios catch 错误返回 JavaScript 错误而不是服务器响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56236538/