diff --git a/plugins/react-native.js b/plugins/react-native.js index 4db0644cd512..8b37f3bf1431 100644 --- a/plugins/react-native.js +++ b/plugins/react-native.js @@ -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); }); } diff --git a/test/plugins/react-native.test.js b/test/plugins/react-native.test.js index 62a205bb8f1f..84064123b71a 100644 --- a/test/plugins/react-native.test.js +++ b/test/plugins/react-native.test.js @@ -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); + }); }); });