美文网首页
ECONNABORTED

ECONNABORTED

作者: 米古月_f198 | 来源:发表于2021-02-02 09:40 被阅读0次

    https://www.cnblogs.com/zhouyangla/p/8757149.html

    //在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);
        });
    });
    
    axios.get('/some/endpoint', { retry: 5, retryDelay: 1000 })
        .then(function(res) {
            console.log('success', res.data);
        })
        .catch(function(err) {
            console.log('failed', err);
        });
    

    https://blog.csdn.net/weixin_44259720/article/details/112854839

    相关文章

      网友评论

          本文标题:ECONNABORTED

          本文链接:https://www.haomeiwen.com/subject/zewetltx.html