Skip to content

Commit 3a3a44b

Browse files
zehZeh Fernando
authored andcommitted
Added ability to keep previous exception handler
This adds a new boolean parameter, `keepPreviousHandler`. When set to true, it stores the previous handler value and calls it after calling the newly set exception handler. This allows developers to keep the previous functionality (red screen) intact, while still capturing errors (i.e. for analytics purposes).
1 parent 9247a8b commit 3a3a44b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
const noop = () => {};
22

3-
export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = false) => {
3+
export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = false, keepPreviousHandler = false) => {
44
const allowed = allowedInDevMode ? true : !__DEV__;
55
if (allowed) {
6-
global.ErrorUtils.setGlobalHandler(customHandler);
6+
if (keepPreviousHandler) {
7+
const previousHandler = global.ErrorUtils.getGlobalHandler();
8+
global.ErrorUtils.setGlobalHandler((error, isFatal) => {
9+
customHandler(error, isFatal);
10+
previousHandler(error, isFatal);
11+
});
12+
} else {
13+
global.ErrorUtils.setGlobalHandler(customHandler);
14+
}
715
} else {
816
console.log('Skipping setJSExceptionHandler: Reason: In DEV mode and allowedInDevMode = false');
917
}

0 commit comments

Comments
 (0)