【发布时间】:2022-01-16 01:32:19
【问题描述】:
这可能看起来很愚蠢,但我试图在 Axios 中请求失败时获取错误数据。
axios
.get('foo.com')
.then((response) => {})
.catch((error) => {
console.log(error); //Logs a string: Error: Request failed with status code 404
});
除了字符串之外,是否有可能获得一个带有状态码和内容的对象?例如:
Object = {status: 404, reason: 'Not found', body: '404 Not found'}
【问题讨论】:
标签: javascript axios