You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
axios.defaults.retry=2;// 在第一个失败的请求之后重试该请求的次数axios.defaults.retryDelay=1000;// 在失败的请求之间等待的毫秒数(默认为1)instance.interceptors.response.use(undefined,(err)=>{const{ config }=err;// If config does not exist or the retry option is not set, rejectif(!config||!config.retry)returnPromise.reject(err);// Set the variable for keeping track of the retry countconfig.__retryCount=config.__retryCount||0;// Check if we've maxed out the total number of retriesif(config.__retryCount>=config.retry){// Reject with the errorreturnPromise.reject(err);}// Increase the retry countconfig.__retryCount+=1;constbackoff=newPromise(((resolve)=>{setTimeout(()=>{resolve();},config.retryDelay||1);}));// Return the promise in which recalls axios to retry the requestreturnbackoff.then(()=>axios(config));});
自定义拦截器
当请求失败的时候进行二次请求
参考自:axios官方github的issue
使用axios下载文件
可以解决下载下来文件为txt的情况;
参考:
The text was updated successfully, but these errors were encountered: