react-native-exception-handler
react-native-exception-handler copied to clipboard
How to exit the app from JS handler?
I am trying to setup both JS and native handlers. But when JS errors occur, it shows the alert box, on clicking "Ok", I would like to kill the app. Not killing it leaves the app in a bad UI state (For example say user is inputing search text and experienced a crash, it leaves the app in the same UI state).
const errorHandler = (e, isFatal) => {
if (isFatal) {
Alert.alert(
'Unexpected error occurred',
`
Error: ${(isFatal) ? 'Fatal:' : ''} ${e.name} ${e.message}
We have reported this to our team ! Please close the app and start again!
`,
[{
text: 'Close'
}]
);
} else {
console.log(e); // So that we can see it in the ADB logs in case of Android if needed
}
};
setJSExceptionHandler(errorHandler);
setNativeExceptionHandler((errorString) => {
console.log('setNativeExceptionHandler');
});