reactjs - 无法在 react-native 中捕获错误
问题描述
如何处理 React-Native 中的错误
所以这是我的错误枚举
export const frontendErrors = {
INVALID_PHONE_NUMBER_ENTERED: 'Sorry you have entered invalid phone number'
}
从我的 phoneAuth.js 文件中,我在这样的 catch 语句中抛出错误
catch (err) {
const errorSearch = 'auth/invalid-phone-number'
if (err.message.includes(errorSearch)) {
throw new Error(frontendErrors.INVALID_PHONE_NUMBER_ENTERED)
}
当我在父组件中发现错误时
catch (error) {
console.log(error)
this.dropDownAlertRef.alertWithType('error', 'Error', error)
}
在日志中,我将错误作为一个对象,就像这样
Error: Sorry you have entered invalid phone number
接受字符串,dropdownAlertRef
因此它正在记录一个空对象,即
this.dropDownAlertRef.alertWithType('error', 'Error', 'Invalid phone number')
这将记录错误。
我尝试了什么?
做,console.log(error.Error)
给出undefined。如何访问我的错误?
解决方案
推荐阅读
- upgrade - 如何在 buildroot 系统上升级库?
- sql - 获取拥有 1,2 和超过 3 种产品的客户数量
- python - 尝试将 sklearn 数据集导入 Jupyter Notebook 时出现 OSError
- excel - Excel 日期公式 + 3 个月
- powershell - 脚本只加载一次哈希表
- python - 文件python中的模式
- python - 使用 Aiofiles 读取文件时的 Python 错误
- android - 如何将 YAML 响应正文解析为 Retrofit 库中的 POJO?
- android - 使用内窥镜拍照以扑动应用程序
- php - 如果客户尚未购买,则隐藏 woocommerce 产品库