Skip to content

Commit d148259

Browse files
robrechtmeRobrecht Meersman
and
Robrecht Meersman
authored
fix: still call console.error when hoisting it (#149)
Co-authored-by: Robrecht Meersman <robrecht.meersman@inthepocket.mobi>
1 parent 8e0ce7a commit d148259

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ const { ReactNativeExceptionHandler } = NativeModules;
55
const noop = () => { };
66

77
export const setJSExceptionHandler = (customHandler = noop, allowedInDevMode = false) => {
8-
if (typeof allowedInDevMode !== "boolean" || typeof customHandler !== "function"){
8+
if (typeof allowedInDevMode !== "boolean" || typeof customHandler !== "function") {
99
console.log("setJSExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean");
1010
console.log("Not setting the JS handler .. please fix setJSExceptionHandler call");
1111
return;
1212
}
1313
const allowed = allowedInDevMode ? true : !__DEV__;
1414
if (allowed) {
1515
global.ErrorUtils.setGlobalHandler(customHandler);
16-
console.error = (message, error) => global.ErrorUtils.reportError(error); // sending console.error so that it can be caught
16+
const consoleError = console.error;
17+
console.error = (...args) => {
18+
global.ErrorUtils.reportError(...args);
19+
consoleError(...args);
20+
};
1721
} else {
1822
console.log("Skipping setJSExceptionHandler: Reason: In DEV mode and allowedInDevMode = false");
1923
}

0 commit comments

Comments
 (0)