bugsnag/bugsnag-js

[React] Render `FallbackComponent` after programmatically notifying Bugsnag of an error

nichita-pasecinic opened this issue · 4 comments

Problem

Currently the FallbackComponent is being rendered when an unhandled error is being caught, but it is not being caught for simply

throw new Error('error')

Because it does not being caught up by window.onerror.

Although there is a necessity to render fallback component when something happened outside render() of the react. Using Bugsnag.notify(...) helps with reporting the errors, but it does not show the error component - which might be desirable.

Possible solution

Would be nice to either parametrize the Bugnsag.notify to show the FallbackComponent or to have a different method over Bugsnag that by invoking it, will render the FallbackComponent

Hi @nichita-pasecinic,

We wrap the React ErrorBoundary component so will therefore display the FallbackComponent under the same conditions that a React app would normally display the ErrorBoundary. https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary

The documentation on how to set this up in BugSnag is here: https://docs.bugsnag.com/platforms/react-native/react-native/capturing-render-errors/

Hope that helps

Hi @johnkiely1,

I do understand that this is a wrap over ErrorBoundary, but this does not help. As error boundary catches just render error, but not custom thrown errors. Maybe is it worth considering wrapping ErrorBoundary and some other component that will listen to custom thrown errors (via Bugnag API, e.g.: Bugsnag.notify(...) or some custom Bugsnag.throwError(...)) - that will render the FallbackComponent

Thanks

If you are deliberately throwing a custom error and you want to have this error appear in Bugsnag you can simply notify Bugsnag with this error at the time it is thrown. The behaviour of a deliberately thrown error triggering a FallbackComponent is outside the scope of what BugSnag does. If you want to trigger your own fallback component you would need to do this via your own code when you throw the error. This is not something we can help with.

Thanks for explanations @johnkiely1!
Will do by myself