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

Finnp patch 1 - Handle error events correctly #164

Merged
merged 4 commits into from
Jul 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ function _createXHR(options) {

function errorFunc(evt) {
clearTimeout(timeoutTimer)
if(!(evt instanceof Error)){
evt = Error("" + (evt || "Unknown XMLHttpRequest Error") )
}
evt.statusCode = 0
return callback(evt, failureResponse)
}
Expand Down Expand Up @@ -149,11 +146,15 @@ function _createXHR(options) {

xhr.onreadystatechange = readystatechange
xhr.onload = loadFunc
xhr.onerror = errorFunc

xhr.onerror = errorFunc.bind({}, Error('Unknown XMLHttpRequest Error'))

xhr.onabort = function(){
aborted = true;
}
xhr.ontimeout = errorFunc

xhr.ontimeout = errorFunc.bind({}, Error('XMLHttpRequest Timeout'))

xhr.open(method, uri, !sync, options.username, options.password)
//has to be after open
if(!sync) {
Expand Down