axios请求失败获取后端接口返回的状态码及错误信息
2019-12-02 本文已影响0人
上海老宅男
axios.get('/ceshi/8888')
.catch(function (error) {
if (error.response) {
var tips = error.response.data.error_description //状态值
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
Message({
message: tips,
type: 'error',
duration: 5 * 1000
})
return Promise.reject(error)
});