大佬教程收集整理的这篇文章主要介绍了node.js – 无法从axios请求中捕获并记录错误响应,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的axios请求
axios.post(Helper.getLoginApi(),data) .then((responsE) => { console.log(responsE); this.props.history.push(from.pathName) }) .catch((error)=> { console.log(error); })
我能够成功地在成功的请求上记录数据.但是,当我故意产生错误并尝试console.log它时,我没有得到结果记录,我只是看到了
但是,当我在Chrome控制台中转到“网络标签”时,我会看到以下回复.
提前感谢您的帮助.
{ // `data` is the response that was provided by the server data: {},// `status` is the http status code from the server response status: 200,// `statusText` is the http status message from the server response statusText: 'OK',// `headers` the headers that the server responded with // All header names are lower cased headers: {},// `config` is the config that was provided to `axios` for the request config: {},// `request` is the request that generated this response // it is the last Clientrequest instance in node.js (in redirects) // and an XMLhttprequest instance the browser request: {} }
所以基本上catch(error =>)实际上只是catch(response =>)
@R_450_10229@以记录error.response.data,你应该能够看到你的回复消息.
axios.post(Helper.getLoginApi(),data) .then((responsE) => { console.log(responsE); this.props.history.push(from.pathName) }) .catch((error)=> { if (error.responsE) { // The request was made and the server responded with a status code // that falls out of the range of 2xx console.log(error.response.data); console.log(error.response.status); console.log(error.response.headers); } else if (error.request) { // The request was made but no response was received // `error.request` is an instance of XMLhttprequest in the browser and an instance of // http.Clientrequest in node.js console.log(error.request); } else { // Something happened in setTing up the request that triggered an Error console.log('Error',error.messagE); } })
以上是大佬教程为你收集整理的node.js – 无法从axios请求中捕获并记录错误响应全部内容,希望文章能够帮你解决node.js – 无法从axios请求中捕获并记录错误响应所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。