Skip to content

Commit 92057fd

Browse files
committed
Rethrow error in the browser on next tick
This achieves the same result as #12 but also works in Firefox.
1 parent 4c22bbc commit 92057fd

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/index.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ export default function catchErrors({ filename, components, imports }) {
1515
try {
1616
return originalRender.apply(this, arguments);
1717
} catch (err) {
18-
if (console.reportErrorsAsExceptions) {
19-
// Stop react-native from triggering its own error handler
20-
console.reportErrorsAsExceptions = false;
21-
console.error(err.stack);
22-
// Reactivate it so other errors are still handled
23-
console.reportErrorsAsExceptions = true;
24-
} else {
25-
console.error(err.stack);
26-
}
18+
setTimeout(() => {
19+
if (typeof console.reportErrorsAsExceptions !== 'undefined') {
20+
// We're in React Native. Don't throw.
21+
// Stop react-native from triggering its own error handler
22+
console.reportErrorsAsExceptions = false;
23+
// Log an error
24+
console.error(err);
25+
// Reactivate it so other errors are still handled
26+
console.reportErrorsAsExceptions = true;
27+
} else {
28+
throw err;
29+
}
30+
});
2731

2832
return React.createElement(ErrorReporter, {
2933
error: err,

0 commit comments

Comments
 (0)