File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ /*global ErrorUtils:false*/
2+
3+ /**
4+ * react-native plugin for Raven
5+ *
6+ * Usage:
7+ * var Raven = require('raven-js');
8+ * require('raven-js/plugins/react-native')(Raven);
9+ */
10+ module . exports = function ( Raven ) {
11+ "use strict" ;
12+
13+ function urlencode ( obj ) {
14+ var pairs = [ ] ;
15+ for ( var key in obj ) {
16+ if ( { } . hasOwnProperty . call ( obj , key ) )
17+ pairs . push ( encodeURIComponent ( key ) + '=' + encodeURIComponent ( obj [ key ] ) ) ;
18+ }
19+ return pairs . join ( '&' ) ;
20+ }
21+
22+ function xhrTransport ( options ) {
23+ options . auth . sentry_data = JSON . stringify ( options . data ) ;
24+
25+ var request = new XMLHttpRequest ( ) ;
26+ request . onreadystatechange = function ( e ) {
27+ if ( request . readyState !== 4 ) {
28+ return ;
29+ }
30+
31+ if ( request . status === 200 ) {
32+ if ( options . onSuccess ) {
33+ options . onSuccess ( ) ;
34+ }
35+ } else {
36+ if ( options . onError ) {
37+ options . onError ( ) ;
38+ }
39+ }
40+ } ;
41+
42+ request . open ( 'GET' , options . url + '?' + urlencode ( options . auth ) ) ;
43+ request . send ( ) ;
44+ }
45+
46+ // react-native doesn't have a document, so can't use default Image
47+ // transport - use XMLHttpRequest instead
48+ Raven . setTransport ( xhrTransport ) ;
49+
50+ ErrorUtils . setGlobalHandler ( Raven . captureException ) ;
51+ } ;
Original file line number Diff line number Diff line change @@ -359,6 +359,21 @@ var Raven = {
359359 return Raven ;
360360 } ,
361361
362+ /**
363+ * Override the default HTTP transport mechanism that transmits data
364+ * to the Sentry server.
365+ *
366+ * @param {function } transport Function invoked instead of the default
367+ * `makeRequest` handler.
368+ *
369+ * @return {Raven }
370+ */
371+ setTransport : function ( transport ) {
372+ globalOptions . transport = transport ;
373+
374+ return Raven ;
375+ } ,
376+
362377 /*
363378 * Get the latest raw exception that was captured by Raven.
364379 *
You can’t perform that action at this time.
0 commit comments