Comparing version 2.2.1 to 2.2.2
18
index.js
@@ -54,7 +54,14 @@ "use strict"; | ||
function _createXHR(options) { | ||
var callback = options.callback | ||
if(typeof callback === "undefined"){ | ||
if(typeof options.callback === "undefined"){ | ||
throw new Error("callback argument missing") | ||
} | ||
var called = false | ||
var callback = function cbOnce(err, response, body){ | ||
if(!called){ | ||
called = true | ||
options.callback(err, response, body) | ||
} | ||
} | ||
function readystatechange() { | ||
@@ -100,4 +107,3 @@ if (xhr.readyState === 4) { | ||
evt.statusCode = 0 | ||
callback(evt, failureResponse) | ||
callback = noop | ||
return callback(evt, failureResponse) | ||
} | ||
@@ -134,5 +140,3 @@ | ||
} | ||
callback(err, response, response.body) | ||
callback = noop | ||
return callback(err, response, response.body) | ||
} | ||
@@ -139,0 +143,0 @@ |
{ | ||
"name": "xhr", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "small xhr abstraction", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -55,2 +55,18 @@ var window = require("global/window") | ||
test("[func] Calls the callback once even if error is thrown issue #127", function(assert) { | ||
var count = 0; | ||
setTimeout(function(){ | ||
assert.equal(count, 1, "expected one call") | ||
assert.end() | ||
},100) | ||
try{ | ||
xhr({ | ||
uri: "instanterror://foo" | ||
}, function(err, resp, body) { | ||
count++; | ||
throw Error("dummy error") | ||
}) | ||
} catch(e){} | ||
}) | ||
test("[func] Times out to an error ", function(assert) { | ||
@@ -57,0 +73,0 @@ xhr({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26077
473