• axios请求超时重新请求


    //在main.js设置全局的请求次数,请求的间隙
    axios.defaults.retry = 4;
    axios.defaults.retryDelay = 1000;
    
    axios.interceptors.response.use(undefined, function axiosRetryInterceptor(err) {
        var config = err.config;
        // If config does not exist or the retry option is not set, reject
        if(!config || !config.retry) return Promise.reject(err);
        
        // Set the variable for keeping track of the retry count
        config.__retryCount = config.__retryCount || 0;
        
        // Check if we've maxed out the total number of retries
        if(config.__retryCount >= config.retry) {
            // Reject with the error
            return Promise.reject(err);
        }
        
        // Increase the retry count
        config.__retryCount += 1;
        
        // Create new promise to handle exponential backoff
        var backoff = new Promise(function(resolve) {
            setTimeout(function() {
                resolve();
            }, config.retryDelay || 1);
        });
        
        // Return the promise in which recalls axios to retry the request
        return backoff.then(function() {
            return axios(config);
        });
    });
  • 相关阅读:
    P1006 传纸条
    P1387 最大正方形
    P1417 烹调方案
    P1052 过河
    P1063 能量项链
    P1736 创意吃鱼法
    P1156 垃圾陷阱
    P1220 关路灯
    @P1373 小a和uim之大逃离
    【leetcode】Interleaving String
  • 原文地址:https://www.cnblogs.com/ivan5277/p/12834802.html
Copyright © 2020-2023  润新知