Skip to content

Use fetch api instead of XHR api#1

Open
nimishsinghal wants to merge 1 commit into
masterfrom
feat-move-XHR-to-fetch
Open

Use fetch api instead of XHR api#1
nimishsinghal wants to merge 1 commit into
masterfrom
feat-move-XHR-to-fetch

Conversation

@nimishsinghal
Copy link
Copy Markdown

Before submitting a pull request, please verify the following:

  • If you've added code that should be tested, please add tests.
  • If you've modified the API (e.g. added a new config or public method), update the docs and TypeScript declaration file.
  • Ensure your code lints and the test suite passes (npm test).

@anubhav7495
Copy link
Copy Markdown

And the browsers that don't support fetch. What about them?

@nimishsinghal
Copy link
Copy Markdown
Author

I think the fetch polyfill wil handle that

Comment thread dist/raven.js
},

_makeRequest: function(opts) {
var request = _window.XMLHttpRequest && new _window.XMLHttpRequest();
Copy link
Copy Markdown

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

Comment thread dist/raven.js

_makeRequest: function(opts) {
var request = _window.XMLHttpRequest && new _window.XMLHttpRequest();
if (!request) return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if not, either return or request a polyfill

Comment thread dist/raven.js
if (!request) return;

// if browser doesn't support CORS (e.g. IE7), we are out of luck
var hasCORS = 'withCredentials' in request || typeof XDomainRequest !== 'undefined';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You also need to handle CORS issue

Comment thread dist/raven.js
.then(function(response) {
opts.onSuccess && opts.onSuccess();
})
.catch(function(response) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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

@anubhav7495
Copy link
Copy Markdown

Please require the polyfill. I don't see it in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants