这可能看起来很蠢,但我正在尝试在Axios请求失败时获取错误数据。
axios
.get('foo.example')
.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'}