Axios的error处理

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

来源:简书

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容