mirror of
https://github.com/cuiocean/ZY-Player.git
synced 2026-05-09 15:52:40 +08:00
动态配置axios超时
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user