在 catch 那里,它返回的是 error.request 错误,所以就在这里做 retry 的功能,经过测试是可以实现重新请求的功功能, 虽然能够实现 超时重新请求的功能,但很麻烦,需要每一个请API的页面里边要设置重新请求。看上面,我这个项目有几十个 .vue 文件,如果每个页面都要去设置超时重新请求的功能,那我要疯掉的.而...
log(error.config); }); 超时之后, 报出 Uncaught (in promise) Error: timeout of xxx ms exceeded的错误。 在catch那里,它返回的是error.request错误,所以就在这里做 retry的功能, 经过测试是可以实现重新请求的功功能, 虽然能够实现 超时重新请求的功能,但很麻烦,需要每一个请API的页面里边要设置重新请求...
// axios-retry 插件 axiosRetry(request, { retries: 3, // 设置重试次数 retryDelay: () => 500, // 设置重试延迟时间 shouldResetTimeout: true, // 重置请求超时时间 // error.code===ECONNABORTED表示请求超时了 ERR_NETWORK网络出错 retryCondition: (error) => ['ECONNABORTED', 'ERR_NETWORK']...
}// Increase the retry countconfig.__retryCount+=1;// Create new promise to handle exponential backoffvarbackoff =newPromise(function(resolve) {setTimeout(function() {resolve(); }, config.retryDelay||1); });// Return the promise in which recalls axios to retry the requestreturnbackoff....
axios.interceptors.request.use(function (config) { // Do something before request is sent return config; }, function (error) { // Do something with request error return Promise.reject(error); }); // Add a response interceptor axios.interceptors.response.use(function (response) { ...
// 请求拦截request.interceptors.request.use((config)=>{if(config.__isRetryRequest){// 这里是针对重试请求的监听logger.info('重试请求',config.url)}returnconfig})// 响应拦截request.interceptors.response.use((res)=>{// 。。。returnres},(error)=>{if(error.code==='ECONNABORTED'){// 监听...
console.log(error.config); }); 超时之后, 报出 Uncaught (in promise) Error: timeout of xxx ms exceeded的错误。 在catch那里,它返回的是error.request错误,所以就在这里做 retry的功能, 经过测试是可以实现重新请求的功功能, 虽然能够实现 超时重新请求的功能,但很麻烦,需要每一个请API的页面里边要设置重...
log(error.config); }); 超时之后, 报出 Uncaught (in promise) Error: timeout of xxx ms exceeded的错误。 在catch那里,它返回的是error.request错误,所以就在这里做 retry的功能, 经过测试是可以实现重新请求的功功能, 虽然能够实现 超时重新请求的功能,但很麻烦,需要每一个请API的页面里边要设置重新请求...
}//Increase the retry countconfig.__retryCount += 1;//Create new promise to handle exponential backoffvarbackoff =newPromise(function(resolve) { setTimeout(function() { resolve(); }, config.retryDelay|| 1); });//Return the promise in which recalls axios to retry the requestreturnback...
超时之后, 报出 Uncaught (in promise) Error: timeout of xxx ms exceeded的错误。 在catch那里,它返回的是error.request错误,所以就在这里做 retry的功能, 经过测试是可以实现重新请求的功功能, 虽然能够实现 超时重新请求的功能,但很麻烦,需要每一个请API的页面里边要设置重新请求。