react-native: [JS] JS API for global handling of unhandled exceptions
The API I envision is similar to window.onerror but not necessarily the same. This would allow us to make RCTExceptionsManager.reportUnhandledException
a lot smaller (we’d move much of the code into JS to keep the current behavior) and make it easier to do custom error handling.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 31 (24 by maintainers)
Links to this issue
Commits related to this issue
- add getter as public api for ErrorUtils._globalHandler Summary:As discussed here #1194 . This add an getter the default handler, so that custom handler can be added (monkey patch?) without overwritin... — committed to facebook/react-native by qbig 8 years ago
- add getter as public api for ErrorUtils._globalHandler Summary:As discussed here #1194 . This add an getter the default handler, so that custom handler can be added (monkey patch?) without overwritin... — committed to pglotov/react-native by qbig 8 years ago
Exactly @qbig
Basically
Then your
BridgeReloader
would be an objC module that simply calls[_bridge reload]
Or in an Android module, you just get the running activity, finish it, and restart it
Here: https://github.com/facebook/react-native/blob/d33b554f5d4bb7856cf2fc21175bab23d8225fe4/packager/react-packager/src/Resolver/polyfills/error-guard.js
‘setGlobalHandler’ would overwrite a lot of the RN behaviour (eg. RedBox in development). Understanding that we could just monkey patch globalHandler, the "" seems alarming. So maybe an API like addGlobalHandler, so that we could add custom handler without breaking the default behaviour and and without messing with “internal” variables ? @ide @satya164
That’s neat:) @ajwhite Thanks so much! I guess you are not using the raven-js plugin? which does something like :
But I don’t like the fact that it is overwriting the default exception handler.
So I was considering something like
This would be great for adding something like Bugsnag to report exceptions when apps are in production.
Edit: In fact, I think
ErrorUtils.setGlobalHandler((err, isFatal) => { ... });
might do the job here.