码迷,mamicode.com
首页 > 移动开发 > 详细

axios 处理超时问题 记录

时间:2020-06-09 14:59:20      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:pat   turn   time   log   res   conf   des   ISE   逻辑   

前言:前两天遇到处理请求超时的逻辑,记录起来。

// 处理超时问题  下面的代码仅在登录的时候做了超时处理,有其他需求的自行修改逻辑
axios.interceptors.response.use(
  (response) => response,
  (error) => {
    const originalRequest = error.config;
    // eslint-disable-next-line no-underscore-dangle
    if (
      error.code === ‘ECONNABORTED‘ &&
      error.message.indexOf(‘timeout‘) !== -1 &&
      // eslint-disable-next-line no-underscore-dangle
      !originalRequest._retry
    ) {
      // 超时逻辑
      const curPath = window.location.hash;
      if (curPath.includes(‘/login‘)) {
        message.error(‘请求超时,请稍后进行操作!’);
      }
    }
    return Promise.reject(error);
  },
);

  

你还差得远呢!

axios 处理超时问题 记录

标签:pat   turn   time   log   res   conf   des   ISE   逻辑   

原文地址:https://www.cnblogs.com/sxdjy/p/13072089.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!