Skip to content

Commit b7ce7e0

Browse files
committed
Make request handler work properly with XDomainRequest
1 parent e19a1b2 commit b7ce7e0

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/raven.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,24 +1584,18 @@ Raven.prototype = {
15841584
if (!hasCORS) return;
15851585

15861586
var url = opts.url;
1587-
function handler() {
1588-
if (request.status === 200) {
1589-
if (opts.onSuccess) {
1590-
opts.onSuccess();
1591-
}
1592-
} else if (opts.onError) {
1593-
var err = new Error('Sentry error code: ' + request.status);
1594-
err.request = request;
1595-
opts.onError(err);
1596-
}
1597-
}
15981587

15991588
if ('withCredentials' in request) {
16001589
request.onreadystatechange = function () {
16011590
if (request.readyState !== 4) {
16021591
return;
1592+
} else if (request.status === 200) {
1593+
opts.onSuccess && opts.onSuccess();
1594+
} else if (opts.onError) {
1595+
var err = new Error('Sentry error code: ' + request.status);
1596+
err.request = request;
1597+
opts.onError(err);
16031598
}
1604-
handler();
16051599
};
16061600
} else {
16071601
request = new XDomainRequest();
@@ -1610,7 +1604,16 @@ Raven.prototype = {
16101604
url = url.replace(/^https?:/, '');
16111605

16121606
// onreadystatechange not supported by XDomainRequest
1613-
request.onload = handler;
1607+
if (opts.onSuccess) {
1608+
request.onload = opts.onSuccess;
1609+
}
1610+
if (opts.onError) {
1611+
request.onerror = function () {
1612+
var err = new Error('Sentry error code: XDomainRequest');
1613+
err.request = request;
1614+
opts.onError(err);
1615+
}
1616+
}
16141617
}
16151618

16161619
// NOTE: auth is intentionally sent as part of query string (NOT as custom

0 commit comments

Comments
 (0)