Skip to content
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

Fixed abort/error/loadend event firing, statusCode on error, exceptions #6

Merged
merged 2 commits into from
Jul 31, 2019

Conversation

wesgarland
Copy link

I had to look at this because my application was hanging indefinitely using this particular XHR lib -- I had a domain name spelled wrong, and neither the error() nor load() events were firing, so my Promise was never resolving nor rejecting.

This fix addresses that problem by correcting the firing order (and ability to fire) of load, loadend, abort and error events. It also fixes the mis-fire of abort in the current driverdan 1.8 (original repo) version of this code that re-presented itself when I fixed abort firing.

A few smaller fixes were made while debugging this; in particular, status is supposed to be zero when the error handler fires, but was set to 503. I left it at 503 for the extra-process request stuff since I didn't have time to give that enough thought.

Also, I made exceptions into instanceof Error so that stack traces work (already done in driverdan code), and I threw all the event firing once readyState=4 on the NodeJS event loop. I left the earlier events alone since putting everything on the event loop was causing firing order issues; no readyState transistions were firing until the readyState was 4. I expect this change will let multiple load/error/abort handlers which await other (non-xhr) events to interoperate better with no correctness impact.

Wes Garland added 2 commits July 17, 2019 11:34
…HTTP errors fire; now always throw new Error() instead of string
Copy link
Owner

@mjwwit mjwwit left a comment

Choose a reason for hiding this comment

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

Thanks for the PR and the great work! ❤️
I'd be happy to merge and release this after you look at the minor suggestions I made.

this.handleError = function(error) {
this.status = 503;
this.handleError = function(error, status) {
this.status = +status || 0;
Copy link
Owner

Choose a reason for hiding this comment

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

Why is there a + in front of status?

@@ -1,7 +1,7 @@
{
"name": "xmlhttprequest-ssl",
"description": "XMLHttpRequest for Node",
"version": "1.5.5",
"version": "1.5.6",
Copy link
Owner

Choose a reason for hiding this comment

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

In my opinion your changes will at least warrant a minor version bump. Technically it should even be a major, but I doubt anyone's really relying on the specific error type or 503 status code being returned. If you could change it to be 1.6.0 that'd be awesome!

@mjwwit
Copy link
Owner

mjwwit commented Jul 31, 2019

I'll merge the PR and make the changes myself. I'll release version 1.6.0 when I'm done.

@mjwwit mjwwit merged commit efc39e9 into mjwwit:master Jul 31, 2019
@wesgarland
Copy link
Author

wesgarland commented Aug 1, 2019 via email

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