I am using RN 0.61.5, and set my custom error handler ErrorUtils.setGlobalHandler(customHandler);.
export const setGlobalErrorHandler = once(nativeModule => {
console.log("inside setGlobalErrorHandler")
const originalHandler = ErrorUtils.getGlobalHandler();
console.log("originalHandler:", originalHandler)
async function handler(error, fatal) {
if (__DEV__) {
console.log("is dev env")
return originalHandler(error, fatal);
}
console.log("inside setGlobalErrorHandler, is not dev env")
if (!isError(error)) {
console.log("is not error type")
await nativeModule.logPromise(`Unknown Error: ${error}`);
return originalHandler(error, fatal);
}
try {
console.log("create JS error")
const stackFrames = await StackTrace.fromError(error, { offline: true });
await nativeModule.recordErrorPromise(createNativeErrorObj(error, stackFrames, false));
} catch (e) {
console.log("met with error:", JSON.stringify(e));
// do nothing
}
return originalHandler(error, fatal);
}
ErrorUtils.setGlobalHandler(handler);
console.log("newHandler:", ErrorUtils.getGlobalHandler())
return handler;
});
Did a small test by throwing a JS error when a button is clicked, but my customHandler does not get invoked. The app doesn't show an RED color error box nor crashes. I am suspecting that some other places are handling the error. I did implement any ErrorBoundary that catches all uncaught errors