Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,36 @@ Raven.prototype = {
});
},

/**
* @param {string} opts.url
* @param {Object} opts.auth
* @param {*} opts.data
* @param {Object} opts.options
* @callback opts.onSuccess
* @callback opts.onError
* @private
*/
_makeRequest: function(opts) {
// NOTE: auth is intentionally sent as part of query string (NOT as custom
// HTTP header) so as to avoid preflight CORS requests
var url = opts.url + '?' + urlencode(opts.auth);

// https://github.com/Modernizr/Modernizr/blob/d5f881a4de0d5fc1af85921ce9c7dc3919c6d335/feature-detects/network/fetch.js
if ('fetch' in _window) {
return _window.fetch(url, {
method: 'POST',
body: stringify(opts.data)
}).then(function (response) {
if (!response.ok) {
return opts.onError && opts.onError(new Error('Sentry error code: ' + response.status))
}

opts.onSuccess && opts.onSuccess();
})["catch"](function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you change })["catch"](function () { to }).catch(function () {
you get an eslint error

opts.onError && opts.onError(new Error('Sentry error code: network unavailable'));
})
}

var request = _window.XMLHttpRequest && new _window.XMLHttpRequest();
if (!request) return;

Expand All @@ -1890,8 +1919,6 @@ Raven.prototype = {

if (!hasCORS) return;

var url = opts.url;

if ('withCredentials' in request) {
request.onreadystatechange = function() {
if (request.readyState !== 4) {
Expand Down Expand Up @@ -1923,9 +1950,7 @@ Raven.prototype = {
}
}

// NOTE: auth is intentionally sent as part of query string (NOT as custom
// HTTP header) so as to avoid preflight CORS requests
request.open('POST', url + '?' + urlencode(opts.auth));
request.open('POST', url);
request.send(stringify(opts.data));
},

Expand Down