提交 b7e19952 编写于 作者: D DCloud_LXH

feat: add uni.interceptors.promiseInterceptor

上级 345d8889
......@@ -2,7 +2,8 @@ const base = [
'base64ToArrayBuffer',
'arrayBufferToBase64',
'addInterceptor',
'removeInterceptor'
'removeInterceptor',
'interceptors'
]
const network = [
......@@ -242,7 +243,7 @@ const third = [
const ad = [
'createRewardedVideoAd',
'createFullScreenVideoAd',
'createInterstitialAd',
'createInterstitialAd',
'createInteractiveAd'
]
......
......@@ -105,7 +105,7 @@ function queue (hooks, data) {
}
if (res === false) {
return {
then () {}
then () { }
}
}
}
......@@ -153,15 +153,15 @@ function getApiInterceptorHooks (method) {
if (hook !== 'returnValue') {
interceptor[hook] = globalInterceptors[hook].slice()
}
})
const scopedInterceptor = scopedInterceptors[method]
if (scopedInterceptor) {
Object.keys(scopedInterceptor).forEach(hook => {
if (hook !== 'returnValue') {
interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook])
}
})
}
})
const scopedInterceptor = scopedInterceptors[method]
if (scopedInterceptor) {
Object.keys(scopedInterceptor).forEach(hook => {
if (hook !== 'returnValue') {
interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook])
}
})
}
return interceptor
}
......@@ -185,10 +185,14 @@ export const promiseInterceptor = {
if (!isPromise(res)) {
return res
}
return res.then(res => {
return res[1]
}).catch(res => {
return res[0]
return new Promise((resolve, reject) => {
res.then(res => {
if (res[0]) {
reject(res[0])
} else {
resolve(res[1])
}
})
})
}
}
}
......@@ -10,4 +10,4 @@ export {
export const interceptors = {
promiseInterceptor
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册