-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Feature/improve xml request error handling (#3947) #4298
Changes from all commits
0f5b63a
a1c0078
1e92833
c53c752
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ HttpProvider.prototype.send = function (payload, callback) { | |
var request = this._prepareRequest(); | ||
|
||
request.onreadystatechange = function() { | ||
if (request.readyState === 4 && request.timeout !== 1) { | ||
if (request.readyState === 4 && request.timeout !== 1 && request.status !== 0) { | ||
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. As per documentation this property returns (HTTP Status Codes)[https://developer.mozilla.org/en-US/docs/Web/HTTP/Status] and there is no status code Do we want to check if the status code exists? if yes then condition should not use a constant zero. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/status 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. Mentioned in the related issue, |
||
var result = request.responseText; | ||
var error = null; | ||
|
||
|
@@ -112,6 +112,16 @@ HttpProvider.prototype.send = function (payload, callback) { | |
} | ||
}; | ||
|
||
//since XHR2._onHttpRequestError swallows the initial request error, we need to get it from the underlying request | ||
request.addEventListener('loadstart', function() { | ||
var clientRequest = request._request; | ||
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 Also the Did you tried top level events 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.
This PR was originally created by @uluhonolulu, and I'm not really sure how to setup an environment to test that this works as intended. However, how we adjust this specific code is dependent on what package we choose to go with 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. why we are binding 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.
@nazarhussain this is my hacky attempt to get the underlying error, because xhr2-cookies just swallows it (see souldreamer/xhr2-cookies#9). 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.
@jdevcs because |
||
if (clientRequest) { | ||
clientRequest.on('error', function (error) { | ||
callback(error || errors.RequestFailed()); | ||
}); | ||
} | ||
}); | ||
|
||
request.ontimeout = function() { | ||
_this.connected = false; | ||
callback(errors.ConnectionTimeout(this.timeout)); | ||
|
@@ -121,7 +131,7 @@ HttpProvider.prototype.send = function (payload, callback) { | |
request.send(JSON.stringify(payload)); | ||
} catch(error) { | ||
this.connected = false; | ||
callback(errors.InvalidConnection(this.host)); | ||
callback(errors.InvalidConnection(this.host, { code: 'ECONNREFUSED', reason: 'ECONNREFUSED' })); | ||
} | ||
}; | ||
|
||
|
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.
@spacesailor24 The PR referred in mentioned to upgrade
xhr2-cookies
tonode-xhr2
. I could not find that change incorporated here. Does the scope for this PR changed?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.
This PR does not include the package switch. What do y'all think about updating the package used?
Current package - Last release 4 years ago
Suggested package - Last release was Feb 9 2021
CC @jdevcs @luu-alex
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.
@spacesailor24 could you check xhr2-cookies vs node-xhr2 with internal Lib Selection Checklist for Web3.js .
( build size impact, ..etc ) , lets open another PR for lib switch, if this lib update is not directly required for fix of xml request error handling ( this PR )
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.
@spacesailor24 BTW node-xhr2 has the same issue (https://github.com/pwnall/node-xhr2/blob/master/src/001-xml_http_request.coffee#L608), but at least it's developed more actively so there's a chance they fix it.
As far as I see, the code looks pretty similar to xhr2-cookies, just rewritten in CoffeeScript.