-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
支付宝端自带request错误捕获行为与微信端不一致 #5249
Comments
CC @Chen-jj |
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
你可以暂时自己先封装一个拦截器,代码如下,可以直接copy // 磨平支付宝和微信request差异
function requestAdapter(options) {
// 解决支付宝GET请求拆分数组参数奇葩行为
if (process.env.TARO_ENV === 'alipay' && options.method === 'GET') {
if (JSON.stringify(options.data) !== '{}') {
const newData = options.data
Object.keys(newData).forEach(key => {
newData[key] = typeof newData[key] === 'string' ? newData[key] : JSON.stringify(newData[key])
})
options.data = newData
}
}
const originSuccess = options['success']
const originFail = options['fail']
const originComplete = options['complete']
let completeData
return new Promise((resolve, reject) => {
options['success'] = res => {
completeData = res
originSuccess && originSuccess(res)
resolve(res)
}
options['fail'] = res => {
// 11:跨域错误 19:http错误
completeData = res
if (process.env.TARO_ENV === 'alipay'
&& res.error
&& [11, 19].indexOf(res.error) !== -1)
{
res.statusCode = res.status
delete res.status
res.header = res.headers
delete res.headers
delete res.error
delete res.errorMessage
originSuccess && originSuccess(res)
resolve(res)
} else {
originFail && originFail(res)
reject(res)
}
}
options['complete'] = res => {
res = res || completeData
originComplete && originComplete(res)
}
Taro.request(options)
})
} |
@sanye33 三爷你的 PR 有个细节有空改下吧,合了后应该这个就没问题了 |
好的,我晚上回去修改提交 |
@sanye33 辛苦辛苦 |
Hello~ 您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。 如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。 Good luck and happy coding~ |
问题描述
微信端401等错误走的是正常success,而且支付宝走的是catch
复现步骤
期望行为
根据issue437,异常状态码不会是走success,但是两端行为不一致
报错信息
系统信息
Taro CLI 1.3.29 environment info:
System:
OS: macOS 10.14.6
Shell: 5.7.1 - /usr/local/bin/zsh
Binaries:
Node: 10.16.0 - /usr/local/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
npmPackages:
@tarojs/async-await: 1.3.29 => 1.3.29
@tarojs/components: 1.3.29 => 1.3.29
@tarojs/components-qa: 1.3.29 => 1.3.29
@tarojs/mobx: 1.3.29 => 1.3.29
@tarojs/mobx-h5: 1.3.29 => 1.3.29
@tarojs/plugin-babel: 1.3.29 => 1.3.29
@tarojs/plugin-csso: 1.3.29 => 1.3.29
@tarojs/plugin-sass: 1.3.29 => 1.3.29
@tarojs/plugin-uglifyjs: 1.3.29 => 1.3.29
@tarojs/router: 1.3.29 => 1.3.29
@tarojs/taro: 1.3.29 => 1.3.29
@tarojs/taro-alipay: 1.3.29 => 1.3.29
@tarojs/taro-h5: 1.3.29 => 1.3.29
@tarojs/taro-qq: 1.3.29 => 1.3.29
@tarojs/taro-quickapp: 1.3.29 => 1.3.29
@tarojs/taro-rn: 1.3.29 => 1.3.29
@tarojs/taro-swan: 1.3.29 => 1.3.29
@tarojs/taro-tt: 1.3.29 => 1.3.29
@tarojs/taro-weapp: 1.3.29 => 1.3.29
@tarojs/webpack-runner: 1.3.29 => 1.3.29
eslint-config-taro: 1.3.29 => 1.3.29
eslint-plugin-taro: 1.3.29 => 1.3.29
nerv-devtools: ^1.5.5 => 1.5.6
nervjs: ^1.5.5 => 1.5.6
stylelint-config-taro-rn: 1.3.29 => 1.3.29
stylelint-taro-rn: 1.3.29 => 1.3.29
补充信息
The text was updated successfully, but these errors were encountered: