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 的時候去處理這個錯誤,但是拿不到這個狀態(tài)碼。但是官網(wǎng)上就是這么用的。
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拿不到
相關(guān)文章:
1. objective-c - iOS開發(fā)支付寶和微信支付完成為什么跳轉(zhuǎn)到了之前開發(fā)的一個app?2. mysql優(yōu)化 - 關(guān)于mysql分區(qū)3. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應(yīng)4. 致命錯誤: Class ’appfacadeTest’ not found5. javascript - ionic2 input autofocus 電腦成功,iOS手機鍵盤不彈出6. python - 管道符和ssh傳文件7. css - 移動端字體設(shè)置問題8. css - 求推薦適用于vue2的框架 像bootstrap這種類型的9. html5 - 如何實現(xiàn)帶陰影的不規(guī)則容器?10. javascript - 循環(huán)嵌套多個promise應(yīng)該如何實現(xiàn)?
