|
| 1 | +import { NativeModules, Platform } from "react-native"; |
1 | 2 |
|
2 | | -import {NativeModules, Platform} from 'react-native'; |
| 3 | +const { ReactNativeExceptionHandler } = NativeModules; |
3 | 4 |
|
4 | | -const {ReactNativeExceptionHandler} = NativeModules; |
| 5 | +const noop = () => { }; |
5 | 6 |
|
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 | + ); |
12 | 21 | return; |
13 | 22 | } |
14 | 23 | const allowed = allowedInDevMode ? true : !__DEV__; |
15 | 24 | if (allowed) { |
16 | 25 | global.ErrorUtils.setGlobalHandler(customHandler); |
17 | 26 | console.error = (message, error) => global.ErrorUtils.reportError(error); // sending console.error so that it can be caught |
18 | 27 | } 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 | + ); |
20 | 31 | } |
21 | 32 | }; |
22 | 33 |
|
23 | 34 | export const getJSExceptionHandler = () => global.ErrorUtils.getGlobalHandler(); |
24 | 35 |
|
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 | + ); |
29 | 51 | return; |
30 | 52 | } |
31 | | - if (Platform.OS === 'ios') { |
32 | | - ReactNativeExceptionHandler.setHandlerforNativeException(customErrorHandler); |
| 53 | + if (Platform.OS === "ios") { |
| 54 | + ReactNativeExceptionHandler.setHandlerforNativeException( |
| 55 | + executeDefaultHandler, |
| 56 | + customErrorHandler |
| 57 | + ); |
33 | 58 | } else { |
34 | | - ReactNativeExceptionHandler.setHandlerforNativeException(forceApplicationToQuit, customErrorHandler); |
| 59 | + ReactNativeExceptionHandler.setHandlerforNativeException( |
| 60 | + executeDefaultHandler, |
| 61 | + forceApplicationToQuit, |
| 62 | + customErrorHandler |
| 63 | + ); |
35 | 64 | } |
36 | 65 | }; |
37 | 66 |
|
|
0 commit comments