-
Notifications
You must be signed in to change notification settings - Fork 0
Use fetch api instead of XHR api #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| /*! Raven.js 3.20.0 (e6baafa) | github.com/getsentry/raven-js */ | ||
| /*! Raven.js 3.20.0 (c54bf6f) | github.com/getsentry/raven-js */ | ||
|
|
||
| /* | ||
| * Includes TraceKit | ||
|
|
@@ -1947,51 +1947,22 @@ Raven.prototype = { | |
| }, | ||
|
|
||
| _makeRequest: function(opts) { | ||
| var request = _window.XMLHttpRequest && new _window.XMLHttpRequest(); | ||
| if (!request) return; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if not, either return or request a polyfill |
||
|
|
||
| // if browser doesn't support CORS (e.g. IE7), we are out of luck | ||
| var hasCORS = 'withCredentials' in request || typeof XDomainRequest !== 'undefined'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also need to handle CORS issue |
||
|
|
||
| if (!hasCORS) return; | ||
|
|
||
| var url = opts.url; | ||
|
|
||
| if ('withCredentials' in request) { | ||
| request.onreadystatechange = function() { | ||
| if (request.readyState !== 4) { | ||
| return; | ||
| } else if (request.status === 200) { | ||
| opts.onSuccess && opts.onSuccess(); | ||
| } else if (opts.onError) { | ||
| var err = new Error('Sentry error code: ' + request.status); | ||
| err.request = request; | ||
| opts.onError(err); | ||
| } | ||
| }; | ||
| } else { | ||
| request = new XDomainRequest(); | ||
| // xdomainrequest cannot go http -> https (or vice versa), | ||
| // so always use protocol relative | ||
| url = url.replace(/^https?:/, ''); | ||
|
|
||
| // onreadystatechange not supported by XDomainRequest | ||
| if (opts.onSuccess) { | ||
| request.onload = opts.onSuccess; | ||
| } | ||
| if (opts.onError) { | ||
| request.onerror = function() { | ||
| var err = new Error('Sentry error code: XDomainRequest'); | ||
| err.request = request; | ||
| opts.onError(err); | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| // 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.send(stringify(opts.data)); | ||
| /* eslint-disable dot-notation */ | ||
| fetch(url + '?' + urlencode(opts.auth), { | ||
| method: 'POST', | ||
| body: stringify(opts.data) | ||
| }) | ||
| .then(function(response) { | ||
| opts.onSuccess && opts.onSuccess(); | ||
| }) | ||
| .catch(function(response) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fetch only rejects in case of network error, scenarios like 404 or else would not trigger this |
||
| var err = new Error('Sentry error code: ' + response.status); | ||
| err.response = response; | ||
| opts.onError(err); | ||
| }); | ||
| /* eslint-enable dot-notation */ | ||
| }, | ||
|
|
||
| _logDebug: function(level) { | ||
|
|
||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,20 @@ | ||
| { | ||
| "@dist/raven.js": { | ||
| "hashes": { | ||
| "sha256": "jYF4nOaEwqkTJLU1wOR0i8npVgKRwlqzOTb6l64UnnQ=", | ||
| "sha512": "Ub9vUbOIAuiyF0yE7dQZTldjWEMiwU3LuATVQZEo8B8gbwS/Urbkx15y2ScrF/eVSx1VaVY5fLWXZb3iqIonww==" | ||
| "sha256": "IVeJrM2u2qn5TdABNivlAs5ZHhwNSjnlPqXF52NFWXE=", | ||
| "sha512": "yH+bmw43vFPXeFmyRrxpadOj3MQzHK4ym8QIh6mRKEd++4d3upNqJJNVypcfS+27AuxCSgIF11zZpiyxtCAsgw==" | ||
| }, | ||
| "type": null, | ||
| "integrity": "sha256-jYF4nOaEwqkTJLU1wOR0i8npVgKRwlqzOTb6l64UnnQ= sha512-Ub9vUbOIAuiyF0yE7dQZTldjWEMiwU3LuATVQZEo8B8gbwS/Urbkx15y2ScrF/eVSx1VaVY5fLWXZb3iqIonww==", | ||
| "integrity": "sha256-IVeJrM2u2qn5TdABNivlAs5ZHhwNSjnlPqXF52NFWXE= sha512-yH+bmw43vFPXeFmyRrxpadOj3MQzHK4ym8QIh6mRKEd++4d3upNqJJNVypcfS+27AuxCSgIF11zZpiyxtCAsgw==", | ||
| "path": "dist/raven.js" | ||
| }, | ||
| "@dist/raven.min.js": { | ||
| "hashes": { | ||
| "sha256": "T6xp+8yRcwkUpnayYg/Q4ghOycPeh+ERquJRxW408QU=", | ||
| "sha512": "J6EJyBgq/iIJKrjme9c/NGQOcEa63VZDLLP8Zx/D3KcZoS2H65CijyRzRMtozBZjGJlJOEbK/AjYzJH+zzgiyg==" | ||
| "sha256": "1oktImFY/vID/TOpBz36pYsYeu3U4r5B+cS7wJAAUhA=", | ||
| "sha512": "f1zGSrHh6eLj7gUIJdfO9p9Y9y5SXV7pf4GuRweDplVOw3f3DYk6Tc4GX/dGsEP+HKUKY5cPteLY13LkDxC6Yg==" | ||
| }, | ||
| "type": null, | ||
| "integrity": "sha256-T6xp+8yRcwkUpnayYg/Q4ghOycPeh+ERquJRxW408QU= sha512-J6EJyBgq/iIJKrjme9c/NGQOcEa63VZDLLP8Zx/D3KcZoS2H65CijyRzRMtozBZjGJlJOEbK/AjYzJH+zzgiyg==", | ||
| "integrity": "sha256-1oktImFY/vID/TOpBz36pYsYeu3U4r5B+cS7wJAAUhA= sha512-f1zGSrHh6eLj7gUIJdfO9p9Y9y5SXV7pf4GuRweDplVOw3f3DYk6Tc4GX/dGsEP+HKUKY5cPteLY13LkDxC6Yg==", | ||
| "path": "dist/raven.min.js" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,5 +98,8 @@ | |
| "path": "./dist/raven.min.js", | ||
| "maxSize": "10 kB" | ||
| } | ||
| ] | ||
| ], | ||
| "dependencies": { | ||
| "whatwg-fetch": "^2.0.3" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check if fetch exists