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);
},
);
你还差得远呢!

浙公网安备 33010602011771号