Skip to content

Commit

Permalink
Merge pull request JakeChampion#36 from github/reject-with-error
Browse files Browse the repository at this point in the history
Reject promise with TypeError for network failures.
  • Loading branch information
dgraham committed Nov 21, 2014
2 parents 502798d + 67152c2 commit e184d6e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -174,7 +174,7 @@
}

xhr.onerror = function() {
reject()
reject(new TypeError('Network request failed'))
}

xhr.open(self.method, self.url)
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down

0 comments on commit e184d6e

Please sign in to comment.