Skip to content

Commit

Permalink
Merge pull request #1421 from didi/fix_proxy_err
Browse files Browse the repository at this point in the history
fix: fix runtime err [can't read property 'success' of undefined]
  • Loading branch information
hiyuki authored Mar 6, 2024
2 parents 0ed5fa5 + 601b777 commit 8dfbc72
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions packages/api-proxy/src/common/js/promisify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getEnvObj, noop } from './utils'
import { getEnvObj } from './utils'

const envObj = getEnvObj()

Expand Down Expand Up @@ -68,25 +68,20 @@ function promisify (listObj, whiteList, customBlackList) {
}

result[key] = function (...args) {
const obj = args[0]
if (promisifyFilter(key) && !(obj.success || obj.fail || obj.complete)) {
if (!args[0]) {
args.unshift({ success: noop, fail: noop })
}
const obj = args[0] || {}
// 不需要转换 or 用户已定义回调,则不处理
if (!promisifyFilter(key) || obj.success || obj.fail) {
return listObj[key].apply(envObj, args)
} else { // 其他情况进行转换
if (!args[0]) args.unshift(obj)
let returned
const promise = new Promise((resolve, reject) => {
obj.success = function (res) {
resolve(res)
}
obj.fail = function (e) {
reject(e)
}
obj.success = resolve
obj.fail = reject
returned = listObj[key].apply(envObj, args)
})
promise.__returned = returned
return promise
} else {
return listObj[key].apply(envObj, args)
}
}
})
Expand Down

0 comments on commit 8dfbc72

Please sign in to comment.