Skip to content

Commit e847225

Browse files
committed
Add react-native plugin
1 parent 38cb3e9 commit e847225

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

plugins/react-native.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
var request = new XMLHttpRequest();
25+
request.onreadystatechange = function (e) {
26+
if (request.readyState !== 4) {
27+
return;
28+
}
29+
30+
if (request.status === 200) {
31+
if (options.onSuccess)
32+
options.onSuccess();
33+
} else if (options.onError) {
34+
options.onError();
35+
}
36+
};
37+
38+
request.open('GET', options.url + '?' + urlencode(options.auth));
39+
request.send();
40+
}
41+
42+
Raven.setTransport = xhrTransport;
43+
44+
ErrorUtils.setGlobalHandler(function (error) {
45+
Raven.captureException(error);
46+
});
47+
};

0 commit comments

Comments
 (0)