-
Notifications
You must be signed in to change notification settings - Fork 134
/
index.js
45 lines (39 loc) · 1.94 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { NativeModules, Platform } from "react-native";
const { ReactNativeExceptionHandler } = NativeModules;
const noop = () => { };
export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = false) => {
if (typeof allowedInDevMode !== "boolean" || typeof customHandler !== "function") {
console.log("setJSExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean");
console.log("Not setting the JS handler .. please fix setJSExceptionHandler call");
return;
}
const allowed = allowedInDevMode ? true : !__DEV__;
if (allowed) {
global.ErrorUtils.setGlobalHandler(customHandler);
const consoleError = console.error;
console.error = (...args) => {
global.ErrorUtils.reportError(...args);
consoleError(...args);
};
} else {
console.log("Skipping setJSExceptionHandler: Reason: In DEV mode and allowedInDevMode = false");
}
};
export const getJSExceptionHandler = () => global.ErrorUtils.getGlobalHandler();
export const setNativeExceptionHandler = (customErrorHandler = noop, forceApplicationToQuit = true, executeDefaultHandler = false) => {
if (typeof customErrorHandler !== "function" || typeof forceApplicationToQuit !== "boolean") {
console.log("setNativeExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean");
console.log("Not setting the native handler .. please fix setNativeExceptionHandler call");
return;
}
if (Platform.OS === "ios") {
ReactNativeExceptionHandler.setHandlerforNativeException(executeDefaultHandler, customErrorHandler);
} else {
ReactNativeExceptionHandler.setHandlerforNativeException(executeDefaultHandler, forceApplicationToQuit, customErrorHandler);
}
};
export default {
setJSExceptionHandler,
getJSExceptionHandler,
setNativeExceptionHandler
};