axios 返回具体错误消息
虽然请求失败了,但是有具体的返回信息但如果直接打印error,会是以下输出其error对象中包含了一个error.response对象,可以获取到具体信息扩展:官网axios.get('/user/12345').catch(function (error) {if (error.response) {// The request was made and the server responded
·
虽然请求失败了,但是有具体的返回信息
但如果直接打印error,会是以下输出
其error对象中包含了一个error.response对象,可以获取到具体信息
扩展:官网
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);
});
更多推荐
已为社区贡献3条内容
所有评论(0)