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

somewhat more detailed error messages #89

Merged
merged 1 commit into from
Sep 14, 2015
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function createXHR(options, callback) {
function errorFunc(evt) {
clearTimeout(timeoutTimer)
if(!(evt instanceof Error)){
evt = new Error("" + (evt || "unknown") )
evt = new Error("" + (evt || "Unknown XMLHttpRequest Error") )
}
evt.statusCode = 0
callback(evt, failureResponse)
Expand Down Expand Up @@ -153,7 +153,7 @@ function createXHR(options, callback) {
timeoutTimer = setTimeout(function(){
aborted=true//IE9 may still call readystatechange
xhr.abort("timeout")
errorFunc();
errorFunc(new Error("XMLHttpRequest timeout"));
}, options.timeout )
}

Expand Down
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test("[func] Times out to an error ", function (assert) {
uri: "/tests-bundle.js?should-take-a-bit-to-parse=1&" + (new Array(300)).join("cachebreaker=" + Math.random().toFixed(5) + "&")
}, function (err, resp, body) {
assert.ok(err instanceof Error, "should return error")
assert.equal(err.message, "XMLHttpRequest timeout")
assert.equal(resp.statusCode, 0)
assert.end()
})
Expand Down Expand Up @@ -110,7 +111,7 @@ test("XDR usage (run on IE8 or 9)", function (assert) {
test("handles errorFunc call with no arguments provided", function (assert) {
var req = xhr({}, function (err) {
assert.ok(err instanceof Error, "callback should get an error")
assert.equal(err.message, "unknown", "error message should say 'unknown'")
assert.equal(err.message, "Unknown XMLHttpRequest Error", "error message incorrect")
})
assert.doesNotThrow(function () {
req.onerror()
Expand Down