Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): 修复3.x版本下使用timeoutInterceptor会抛出异常的问题 #6802

Merged
merged 2 commits into from
Jun 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions packages/taro-api/src/interceptor/interceptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ export function timeoutInterceptor (chain) {
reject(new Error('网络链接超时,请稍后再试!'))
}, (requestParams && requestParams.timeout) || 60000)

chain
.proceed(requestParams)
.then(res => {
if (!timeout) return
clearTimeout(timeout)
resolve(res)
})
.catch(err => {
timeout && clearTimeout(timeout)
reject(err)
})
p = chain.proceed(requestParams)
p.then(res => {
if (!timeout) return
clearTimeout(timeout)
resolve(res)
}).catch(err => {
timeout && clearTimeout(timeout)
reject(err)
})
})
if (typeof p.abort === 'function') res.abort = p.abort

if (p !== undefined && typeof p.abort === 'function') res.abort = p.abort
return res
}

Expand Down