File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-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+ } ;
You can’t perform that action at this time.
0 commit comments