美文网首页
Axios的error处理

Axios的error处理

作者: 爱笑的小白菜 | 来源:发表于2019-05-16 10:13 被阅读0次

    工作中碰到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);

             }elseif(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);

     });

    作者:一个废人

    链接:https://www.jianshu.com/p/45332e70beaa

    来源:简书

    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

    相关文章

      网友评论

          本文标题:Axios的error处理

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