Skip to content

Commit 3fe1845

Browse files
committed
Additional options for the react native plugin
`pathStrip`: A RegExp that matches the portions of a file URI that should be removed from stacks prior to submission. `preventDefault`: Pass true if you DO NOT wish for Raven to call the original global exception handler (e.g. don't crash the app).
1 parent 3abd8ba commit 3fe1845

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

plugins/react-native.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,30 @@
55
*
66
* Usage:
77
* var Raven = require('raven-js');
8-
* require('raven-js/plugins/react-native')(Raven);
8+
* Raven.addPlugin(require('raven-js/plugins/react-native'));
9+
*
10+
* Options:
11+
*
12+
* pathStrip: A RegExp that matches the portions of a file URI that should be
13+
* removed from stacks prior to submission.
14+
*
15+
* preventDefault: Pass true if you DO NOT wish for Raven to call the original
16+
* global exception handler (e.g. don't crash the app).
917
*/
1018
'use strict';
1119

12-
var DEVICE_PATH_RE = /^\/var\/mobile\/Containers\/Bundle\/Application\/[^\/]+\/[^\.]+\.app/;
13-
function normalizeUrl(url) {
14-
return url
15-
.replace(/^file\:\/\//, '')
16-
.replace(DEVICE_PATH_RE, '');
17-
}
20+
var PATH_STRIP_RE = /^\/var\/mobile\/Containers\/Bundle\/Application\/[^\/]+\/[^\.]+\.app/;
21+
22+
function reactNativePlugin(Raven, pluginOptions) {
23+
pluginOptions = pluginOptions || {};
24+
25+
var pathStrip = pluginOptions.pathStrip || PATH_STRIP_RE;
26+
function normalizeUrl(url) {
27+
return url
28+
.replace(/^file\:\/\//, '')
29+
.replace(pathStrip, '');
30+
}
1831

19-
function reactNativePlugin(Raven) {
2032
function urlencode(obj) {
2133
var pairs = [];
2234
for (var key in obj) {
@@ -75,7 +87,9 @@ function reactNativePlugin(Raven) {
7587

7688
ErrorUtils.setGlobalHandler(function(){
7789
var error = arguments[0];
78-
defaultHandler.apply(this, arguments)
90+
if (!pluginOptions.preventDefault) {
91+
defaultHandler.apply(this, arguments)
92+
}
7993
Raven.captureException(error);
8094
});
8195
}

0 commit comments

Comments
 (0)