diff --git a/src/lib/site/tools.js b/src/lib/site/tools.js index 3c89a5c..1a5897d 100644 --- a/src/lib/site/tools.js +++ b/src/lib/site/tools.js @@ -15,7 +15,8 @@ var session = win.webContents.session var ElectronProxyAgent = require('electron-proxy-agent') // 请求超时时限 -axios.defaults.timeout = 10000 // 可能使用代理,增长超时 +//axios.defaults.timeout = 10000 // 可能使用代理,增长超时 +const TIMEOUT = 6000 // 重试次数,共请求3次 axios.defaults.retry = 2 @@ -23,6 +24,18 @@ axios.defaults.retry = 2 // 请求的间隙 axios.defaults.retryDelay = 1000 +//使用请求拦截器动态调整超时 +axios.interceptors.request.use(function (config) { + if (config.__retryCount === undefined) { + config.timeout = TIMEOUT + } else { + config.timeout = TIMEOUT * (config.__retryCount + 1) + } + return config +}, function (err) { + return Promise.reject(err) +}) + // 添加响应拦截器 axios.interceptors.response.use(function (response) { return response