reactjs - 如何禁用显示“未处理的拒绝(错误):XXXXX”的反应开发错误面板?
问题描述
Unhandled Rejection (Error): User does not exist
(anonymous function)
src/service/index.ts:102
99 | if (customConfig.rawData) return res.data
100 | if (res.data.code != 0) {
101 | const message = res.data.msg || `Api Error:code - ${res.data.code}`
> 102 | const error = new Error(message)
| ^ 103 | ;(error as any).response = res
104 | ;(error as any).config = res.config
105 | ;(error as any).response = res
View compiled
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error. Click the 'X' or hit ESC to dismiss this message.
当出现 api 错误并通过窗口上的事件“unhandledrejection”捕获该错误时,我会抛出错误。但是在反应应用程序中,有一个如图所示的开发错误提示面板。我怎样才能禁用它,我不需要它。
解决方案
您可以使用react-app-rewired
调整CRA
配置
https://github.com/timarney/react-app-rewired
这是你的config-overrides.js
文件
module.exports = (config) => {
const refreshPlugin = config.plugins.find((plugin) => plugin?.constructor?.name === 'ReactRefreshPlugin')
if (refreshPlugin) {
refreshPlugin.options.overlay = false
}
return config
}
推荐阅读
- javascript - 提升一个状态,以便我可以使用 onPress 对其进行修改
- oauth-2.0 - eBay API 错误:授权引发以下错误....无效授权,无效客户端
- ios - 在 Go Server 中为 IOS 生成订阅报价签名时出现问题
- r - 错误:“matlib”的包或命名空间加载失败
- terraform - 如何使用 Terraform Cloud 中设置的环境变量?
- python - 在 python 中使用带有多线程的 opencv2 时 CPU 使用率非常高
- python - 交替元组的numpy数组
- visual-studio - Visual Studio 2019 proto 文件语法高亮?
- scala - Spark JDBC 保存到 HDFS 性能
- kubernetes - 无法在代理后面的 Windows 上检索 okteto 所需的文件