javascript - axios错误处理的对象error.response 是空
问题描述
_this.$http.post(`/company/${id}/out`, { access_token: _this.access_token,}).then((res) => { let info = res;}).catch((err) => { console.log(err.response); // err.response 是 undefined})},

我想在 403 或者 401 的时候去处理这个错误,但是拿不到这个状态码。但是官网上就是这么用的。
axios.get(’/user/12345’) .catch(function (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); } console.log(error.config); });
我的axios 的版本是 ^0.16.1。
问题解答
回答1:403不清楚,但是我记得之前我查的答案是401会被浏览器拦截处理掉,js拿不到
相关文章:
1. python - pyspider的分布式运行成功,2台slave跑,但是时间并没有缩短问题?2. vim - YouCompleteMe 怎么自动补全css属性和属性值?3. ,我写的代码哪里出错了?为什么就是显示不出来peter?4. $fields = $values = [];这条代码一直定义不了,一直报错,老师的源码也是被报错的,执行不了,请问该怎么解决这个问题5. java - 为什么spring的提交格式有些不一样?6. Ant design vue中的联动选择取消操作7. python - Django中如何使用异步8. docker不显示端口映射呢?9. node.js - session怎么存到cookie,然后服务器重启后还能获取。数据库不用mongodb或redis,数据库是mysql10. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?

网公网安备