1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > axios请求失败 如何获取接口返回的状态码及错误信息

axios请求失败 如何获取接口返回的状态码及错误信息

时间:2024-03-07 07:39:15

相关推荐

axios请求失败 如何获取接口返回的状态码及错误信息

如果axios请求失败,如何获取接口返回的状态码及错误信息?

方法如下

axios.get('api/test').then((res) => {console.log(res)).catch((error) => {if (error.response) {// The request was made and the server responded with a status code// that falls out of the range of 2xxconsole.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.jsconsole.log(error.request);} else {// Something happened in setting up the request that triggered an Errorconsole.log('Error', error.message);}console.log(error.config);});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。