Skip to content

Commit a47d8d4

Browse files
committed
Don't call out to the default handle in production mode
1 parent 85d122a commit a47d8d4

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

plugins/react-native.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ function reactNativePlugin(Raven, options) {
5858

5959
ErrorUtils.setGlobalHandler(function() {
6060
var error = arguments[0];
61-
defaultHandler.apply(this, arguments)
61+
// We only call the default handler in development mode so that you are
62+
// presented with the redbox. Calling the default handler in production
63+
// will trigger an Objective-C exception and crash the app.
64+
if ('__DEV__' in global && global.__DEV__) {
65+
defaultHandler.apply(this, arguments)
66+
}
6267
Raven.captureException(error);
6368
});
6469
}

test/plugins/react-native.test.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ describe('React Native plugin', function () {
135135
}
136136
});
137137

138-
it('should call the default React Native handler and Raven.captureException', function () {
138+
it('should call the default React Native handler and Raven.captureException in development mode', function () {
139+
global.__DEV__ = true;
139140
reactNativePlugin(Raven);
140141
var err = new Error();
141142
this.sinon.stub(Raven, 'captureException');
@@ -146,5 +147,17 @@ describe('React Native plugin', function () {
146147
assert.isTrue(Raven.captureException.calledOnce);
147148
assert.equal(Raven.captureException.getCall(0).args[0], err);
148149
});
150+
151+
it('should not call the default React Native handler and Raven.captureException in production mode', function () {
152+
global.__DEV__ = false;
153+
reactNativePlugin(Raven);
154+
var err = new Error();
155+
this.sinon.stub(Raven, 'captureException');
156+
157+
this.globalErrorHandler(err);
158+
159+
assert.equal(this.defaultErrorHandler.callCount, 0);
160+
assert.equal(Raven.captureException.callCount, 1);
161+
});
149162
});
150163
});

0 commit comments

Comments
 (0)