美文网首页
axios请求失败获取后端接口返回的状态码及错误信息

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

作者: 上海老宅男 | 来源:发表于2019-12-02 15:29 被阅读0次
axios.get('/ceshi/8888')
  .catch(function (error) {
  if (error.response) {
    var tips = error.response.data.error_description    //状态值 
    console.log(error.response.data);
    console.log(error.response.status);
    console.log(error.response.headers);
  } else if (error.request) {
    console.log(error.request);
  } else {
    // Something happened in setting up the request that triggered an Error
    console.log('Error', error.message);
  }
  Message({
    message: tips,
    type: 'error',
    duration: 5 * 1000
  })
  return Promise.reject(error)
 });

相关文章

网友评论

      本文标题:axios请求失败获取后端接口返回的状态码及错误信息

      本文链接:https://www.haomeiwen.com/subject/auhfgctx.html