美文网首页
Axios的error处理

Axios的error处理

作者: 一个废人 | 来源:发表于2018-03-12 11:48 被阅读945次

工作中碰到error的处理问题,需要分不同的statusCode进行不同的错误提示。

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

相关文章

网友评论

      本文标题:Axios的error处理

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