|
5 | 5 | *
|
6 | 6 | * Usage:
|
7 | 7 | * 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). |
9 | 17 | */
|
10 | 18 | 'use strict';
|
11 | 19 |
|
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 | + } |
18 | 31 |
|
19 |
| -function reactNativePlugin(Raven) { |
20 | 32 | function urlencode(obj) {
|
21 | 33 | var pairs = [];
|
22 | 34 | for (var key in obj) {
|
@@ -75,7 +87,9 @@ function reactNativePlugin(Raven) {
|
75 | 87 |
|
76 | 88 | ErrorUtils.setGlobalHandler(function(){
|
77 | 89 | var error = arguments[0];
|
78 |
| - defaultHandler.apply(this, arguments) |
| 90 | + if (!pluginOptions.preventDefault) { |
| 91 | + defaultHandler.apply(this, arguments) |
| 92 | + } |
79 | 93 | Raven.captureException(error);
|
80 | 94 | });
|
81 | 95 | }
|
|
0 commit comments