diff --git a/fetch.js b/fetch.js index 3703cd9e..c8ccea38 100644 --- a/fetch.js +++ b/fetch.js @@ -162,7 +162,7 @@ xhr.onload = function() { var status = (xhr.status === 1223) ? 204 : xhr.status if (status < 100 || status > 599) { - reject() + reject(new TypeError('Network request failed')) return } var options = { @@ -174,7 +174,7 @@ } xhr.onerror = function() { - reject() + reject(new TypeError('Network request failed')) } xhr.open(self.method, self.url) diff --git a/test/test.js b/test/test.js index 1272209f..6540b4d2 100644 --- a/test/test.js +++ b/test/test.js @@ -54,8 +54,8 @@ asyncTest('rejects promise for network error', 1, function() { fetch('/error').then(function(response) { ok(false, 'HTTP status ' + response.status + ' was treated as success') start() - }).catch(function() { - ok(true) + }).catch(function(error) { + ok(error instanceof TypeError, 'Rejected with Error') start() }) })