Skip to content

Don't call out to the default handler in production mode #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugins/react-native.js
Original file line number Diff line number Diff line change
@@ -58,7 +58,12 @@ function reactNativePlugin(Raven, options) {

ErrorUtils.setGlobalHandler(function() {
var error = arguments[0];
defaultHandler.apply(this, arguments)
// We only call the default handler in development mode so that you are
// presented with the redbox. Calling the default handler in production
// will trigger an Objective-C exception and crash the app.
if ('__DEV__' in global && global.__DEV__) {
defaultHandler.apply(this, arguments)
}
Raven.captureException(error);
});
}
15 changes: 14 additions & 1 deletion test/plugins/react-native.test.js
Original file line number Diff line number Diff line change
@@ -135,7 +135,8 @@ describe('React Native plugin', function () {
}
});

it('should call the default React Native handler and Raven.captureException', function () {
it('should call the default React Native handler and Raven.captureException in development mode', function () {
global.__DEV__ = true;
reactNativePlugin(Raven);
var err = new Error();
this.sinon.stub(Raven, 'captureException');
@@ -146,5 +147,17 @@ describe('React Native plugin', function () {
assert.isTrue(Raven.captureException.calledOnce);
assert.equal(Raven.captureException.getCall(0).args[0], err);
});

it('should not call the default React Native handler and Raven.captureException in production mode', function () {
global.__DEV__ = false;
reactNativePlugin(Raven);
var err = new Error();
this.sinon.stub(Raven, 'captureException');

this.globalErrorHandler(err);

assert.equal(this.defaultErrorHandler.callCount, 0);
assert.equal(Raven.captureException.callCount, 1);
});
});
});