axios 处理超时问题 记录

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

// 处理超时问题  下面的代码仅在登录的时候做了超时处理,有其他需求的自行修改逻辑
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);
  },
);

  

你还差得远呢!

posted @ 2020-06-09 13:35  玛卡巴鉲  阅读(466)  评论(0编辑  收藏  举报