Skip to content

Commit 86dcd5a

Browse files
committed
make the execution of the previously defined handler optional
1 parent 56914cf commit 86dcd5a

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

index.js

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,66 @@
1+
import { NativeModules, Platform } from "react-native";
12

2-
import {NativeModules, Platform} from 'react-native';
3+
const { ReactNativeExceptionHandler } = NativeModules;
34

4-
const {ReactNativeExceptionHandler} = NativeModules;
5+
const noop = () => { };
56

6-
const noop = () => {};
7-
8-
export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = false) => {
9-
if ((typeof allowedInDevMode !== 'boolean') || (typeof customHandler !== 'function')) {
10-
console.log('setJSExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean');
11-
console.log('Not setting the JS handler .. please fix setJSExceptionHandler call');
7+
export const setJSExceptionHandler = (
8+
customHandler = noop,
9+
allowedInDevMode = false
10+
) => {
11+
if (
12+
typeof allowedInDevMode !== "boolean" ||
13+
typeof customHandler !== "function"
14+
) {
15+
console.log(
16+
"setJSExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean"
17+
);
18+
console.log(
19+
"Not setting the JS handler .. please fix setJSExceptionHandler call"
20+
);
1221
return;
1322
}
1423
const allowed = allowedInDevMode ? true : !__DEV__;
1524
if (allowed) {
1625
global.ErrorUtils.setGlobalHandler(customHandler);
1726
console.error = (message, error) => global.ErrorUtils.reportError(error); // sending console.error so that it can be caught
1827
} else {
19-
console.log('Skipping setJSExceptionHandler: Reason: In DEV mode and allowedInDevMode = false');
28+
console.log(
29+
"Skipping setJSExceptionHandler: Reason: In DEV mode and allowedInDevMode = false"
30+
);
2031
}
2132
};
2233

2334
export const getJSExceptionHandler = () => global.ErrorUtils.getGlobalHandler();
2435

25-
export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplicationToQuit = true) => {
26-
if ((typeof customErrorHandler !== 'function') || (typeof forceApplicationToQuit !== 'boolean')) {
27-
console.log('setNativeExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean');
28-
console.log('Not setting the native handler .. please fix setNativeExceptionHandler call');
36+
export const setNativeExceptionHandler = (
37+
customErrorHandler = noop,
38+
forceApplicationToQuit = true,
39+
executeDefaultHandler = false
40+
) => {
41+
if (
42+
typeof customErrorHandler !== "function" ||
43+
typeof forceApplicationToQuit !== "boolean"
44+
) {
45+
console.log(
46+
"setNativeExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean"
47+
);
48+
console.log(
49+
"Not setting the native handler .. please fix setNativeExceptionHandler call"
50+
);
2951
return;
3052
}
31-
if (Platform.OS === 'ios') {
32-
ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler);
53+
if (Platform.OS === "ios") {
54+
ReactNativeExceptionHandler.setHandlerforNativeException(
55+
executeDefaultHandler,
56+
customErrorHandler
57+
);
3358
} else {
34-
ReactNativeExceptionHandler.setHandlerforNativeException(forceApplicationToQuit, customErrorHandler);
59+
ReactNativeExceptionHandler.setHandlerforNativeException(
60+
executeDefaultHandler,
61+
forceApplicationToQuit,
62+
customErrorHandler
63+
);
3564
}
3665
};
3766

0 commit comments

Comments
 (0)