From ce8d7c55dc13990def7f86f581ca99edf049f4b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Blyz=CC=8Ce=CC=87?= Date: Tue, 28 Jul 2015 17:34:50 +0300 Subject: [PATCH] somewhat more detailed error messages --- index.js | 4 ++-- test/index.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 9ee9889..c62b448 100644 --- a/index.js +++ b/index.js @@ -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) @@ -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 ) } diff --git a/test/index.js b/test/index.js index 5abcac4..852ab33 100644 --- a/test/index.js +++ b/test/index.js @@ -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() }) @@ -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()