Skip to content
Closed
Show file tree
Hide file tree
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
Expand Up @@ -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);
});
}
Expand Down
15 changes: 14 additions & 1 deletion test/plugins/react-native.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
});
});
});