如何禁用显示"未处理的拒绝(错误):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错误时,我抛出错误,并通过窗口上的事件"unhandledrepjection"来捕捉它。但是在react应用程序中,有一个dev错误提示面板,如图所示。我怎么能禁用它,我不需要它。

您可以使用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
}

相关内容

最新更新