Skip to content

Catch XHR errors #222

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

Merged
merged 2 commits into from
Aug 20, 2018
Merged

Catch XHR errors #222

merged 2 commits into from
Aug 20, 2018

Conversation

dirkluijk
Copy link
Contributor

@dirkluijk dirkluijk commented Aug 17, 2018

When the XHR request throws an error (e.g. in case of CORS issues), it is now catched properly. Needed to fix weird Karma/Jasmine issues in Angular CLI projects.

Closes angular/angular-cli#7296.

var xhr = new XMLHttpRequest();
xhr.open('GET', path, false);
xhr.send(null);
var contents = null

Choose a reason for hiding this comment

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

Don't redeclare contents here.

try {
// Use SJAX if we are in the browser
var xhr = new XMLHttpRequest();
xhr.open('GET', path, false);

Choose a reason for hiding this comment

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

Please add a comment like
// Note: synchronous XHR
It's very weird so a comment would alert readers that it is intended.

or you could use /** async */ false in the call.

@dirkluijk
Copy link
Contributor Author

I did not change any of the original code in this PR, just added the try/catch. But of course I can have a look at it.

@dirkluijk
Copy link
Contributor Author

@johnjbarton fixed.

@LinusU
Copy link
Collaborator

LinusU commented Aug 20, 2018

Looks great! Thanks, added a commit to refactor the try/catch, will merge when CI is green 👍

@LinusU LinusU merged commit d665b19 into evanw:master Aug 20, 2018
@dirkluijk
Copy link
Contributor Author

Thanks! 👍

@duydnguyen07
Copy link

@LinusU When are you planning to make a release that will contain this commit?

@dirkluijk dirkluijk deleted the xhr-error-catch branch August 20, 2018 11:34
@LinusU
Copy link
Collaborator

LinusU commented Aug 20, 2018

Thx ❤️ released as 0.5.9 🚀

edit: @duydnguyen07 yes ☺️ took a bit longer since I had a problem with the build script 👌

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.

Regression wrong error message during tests if runtime error occurs after constructor
4 participants