HarmonyOS (react-native)promise.reject抛出异常对象只能接收到message参数
turboModule.ts使用promise.reject抛出异常对象。
checkDeviceSupportLocalAuthenticationWithBiometricsOnly(bool: boolean): Promise<{
code?: number | undefined;
errorCode?: string | undefined;
note?: string | undefined
}> {
try {
userAuth.getAvailableStatus(userAuth.UserAuthType.FINGERPRINT, userAuth.AuthTrustLevel.ATL2);
return Promise.resolve({})
} catch (error) {
try {
userAuth.getAvailableStatus(userAuth.UserAuthType.FACE, userAuth.AuthTrustLevel.ATL2);
return Promise.resolve({})
} catch (error) {
// 如果仅支持生物方式,则不考虑密码
if (bool) {
return Promise.reject({code: 0, message: '该设备暂不支持生物认证'})
}else {
try {
userAuth.getAvailableStatus(userAuth.UserAuthType.PIN, userAuth.AuthTrustLevel.ATL2);
return Promise.resolve({})
}catch (error) {
return Promise.reject({code: 0, message: '该设备暂不支持生物认证'})
}
}
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
在rn catch接收参数时只能拿到message参数:
static checkDeviceSupportLocalAuthenticationWithBiometricsOnly = (biometricsOnly: boolean, callback: (obj: {
code?: number,
errorCode?: string,
note?: string
}) => void) => {
RNLocalAuthentication?.checkDeviceSupportLocalAuthenticationWithBiometricsOnly(biometricsOnly)
.then(() => {
callback({ code: 1 })
}).catch(({ code, message }) => {
console.log(`====>>>>指纹认证失败,code:${code},message:${message}`)
callback({ code, note: message })
});
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS react-native应用编译失败
853浏览 • 1回复 待解决
HarmonyOS react-native如何自行打包
1160浏览 • 1回复 待解决
HarmonyOS react-native集成问题
859浏览 • 1回复 待解决
HarmonyOS 如何hook react-native的NativeModules
941浏览 • 1回复 待解决
HarmonyOS react-native工程使用yarn install报错
879浏览 • 1回复 待解决
HarmonyOS 使用react-native中的Image问题
731浏览 • 1回复 待解决
HarmonyOS react-native项目引用native-stack插件失败
1042浏览 • 1回复 待解决
鸿蒙生态中有没有react-native适配?
14400浏览 • 1回复 待解决
HarmonyOS对接react-native,HarmonyOS侧相关的技术文档
1847浏览 • 1回复 待解决
HarmonyOS RN reject异常问题
645浏览 • 1回复 待解决
HarmonyOS RN:patch-package react-native版本不匹配问题
1510浏览 • 1回复 待解决
react-native 第三方库使用npm更新
2158浏览 • 1回复 待解决
react-native 如何监听HarmonyOS侧滑返回或者点击系统返回键
1601浏览 • 1回复 待解决
HarmonyOS react-native空工程使用Metro服务来加载bundle包失败
1040浏览 • 1回复 待解决
HarmonyOS @ant-design/react-native部分组件转换后无分正常使用
859浏览 • 1回复 待解决
HarmonyOS跑react-native编译的jsbundle包无法在模拟器上运行
734浏览 • 1回复 待解决
HarmonyOS Navigation使用系统路由表,页面无法接收到参数
720浏览 • 1回复 待解决
HarmonyOS React-Native Image组件如何访问harmony目录的resource/media下的图片资源
1421浏览 • 1回复 待解决
nova7Pro需要升级到最新的147系统版本才能接收到鸿蒙推送吗?
7990浏览 • 1回复 待解决
HarmonyOS 捕获异常再抛出为什么报错
904浏览 • 1回复 待解决
HarmonyOS 如何使用BusinessError设置code码并抛出异常?
1130浏览 • 1回复 待解决
调用 window.getWindowAvoidArea 时抛出异常
2561浏览 • 1回复 待解决
HarmonyOS 适配 React native
1198浏览 • 1回复 待解决
HarmonyOS 集成@react-native-oh-tpl/react-native-spinkit报错
1035浏览 • 1回复 待解决
HarmonyOS 无法安装@react-native-oh-tpl/react-native-reanimated
1434浏览 • 1回复 待解决
这个问题是RN内部的规范,当前RN版本规定只能返回字符串,或者返回的对象中包含“message: string”字段。可以通过以下方法进行规避:在原生侧将结果对象转换为JSON字符串返回,JS侧再通过解析JSON,将对象解析出来。