我无法使用 axios 获取 500 错误
中的响应文本。
在开发工具的“网络”选项卡中,我可以找到这样的错误消息
{"Message":"500 error message 0","Code":0,"Type":"error"}
我使用
axios()
.then(function(done) {
//fine and can get done.data
})
.catch(function(error) {
console.log(error.message);
});
但我只能得到
Request failed with status code 500
那么如何使用 axios 获取响应文本
最佳答案
根据axios readme :
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);
});
关于javascript - 如何使用axios处理500错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56577124/