提交 e184d6e3 编写于 作者: D David Graham

Merge pull request #36 from github/reject-with-error

Reject promise with TypeError for network failures.
...@@ -162,7 +162,7 @@ ...@@ -162,7 +162,7 @@
xhr.onload = function() { xhr.onload = function() {
var status = (xhr.status === 1223) ? 204 : xhr.status var status = (xhr.status === 1223) ? 204 : xhr.status
if (status < 100 || status > 599) { if (status < 100 || status > 599) {
reject() reject(new TypeError('Network request failed'))
return return
} }
var options = { var options = {
...@@ -174,7 +174,7 @@ ...@@ -174,7 +174,7 @@
} }
xhr.onerror = function() { xhr.onerror = function() {
reject() reject(new TypeError('Network request failed'))
} }
xhr.open(self.method, self.url) xhr.open(self.method, self.url)
......
...@@ -54,8 +54,8 @@ asyncTest('rejects promise for network error', 1, function() { ...@@ -54,8 +54,8 @@ asyncTest('rejects promise for network error', 1, function() {
fetch('/error').then(function(response) { fetch('/error').then(function(response) {
ok(false, 'HTTP status ' + response.status + ' was treated as success') ok(false, 'HTTP status ' + response.status + ' was treated as success')
start() start()
}).catch(function() { }).catch(function(error) {
ok(true) ok(error instanceof TypeError, 'Rejected with Error')
start() start()
}) })
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册