这看起来可能很愚蠢,但是当Axios中的请求失败时,我会try 获取错误数据.
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'}