3

Unhandled Rejection (Error)

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.

I throw error when get a api error and catch that by event 'unhandledrejection' on window. But in a react application, there is a dev error tips panel as shown. How can i disable it, i don't need it.

Spray Lee
  • 31
  • 3
  • react is warning you that promise error in your code is not handled. It says `User` does not exist, so what you are trying to access is currently not exist. You have to show the `fetch` code for more clarity. Besides you should not ignore errors like this if you want the site to work properly – wyfy Aug 20 '20 at 14:05
  • 1
    Error is expecte, and i will handle it on window 'unhandledrejection' event. But even though i listened the event and prevent the event on window. The error panel is still on display . – Spray Lee Aug 21 '20 at 02:30
  • I would also love to have a solution for this since i use an sdk which involves a small portion of code that is triggering an exception which is not handeled and catching it does still show the Unhandled rejection panel :/ – Mssm Apr 08 '21 at 17:10

1 Answers1

1

You can use react-app-rewired to tweak CRA config https://github.com/timarney/react-app-rewired

Here is your config-overrides.js file

module.exports = (config) => {
  const refreshPlugin = config.plugins.find((plugin) => plugin?.constructor?.name === 'ReactRefreshPlugin')

  if (refreshPlugin) {
    refreshPlugin.options.overlay = false
  }

  return config
}
ZhenyaUsenko
  • 393
  • 4
  • 8