Skip to content

Commit

Permalink
Add a convenience ok getter on Response
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-andrews committed Jan 27, 2015
1 parent 2d2ba78 commit 6057055
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
this.type = 'default'
this.url = null
this.status = options.status
this.ok = this.status >= 200 && this.status < 300;
this.statusText = options.statusText
this.headers = options.headers
this.url = options.url || ''
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function readBlobAsBytes(blob) {
test('resolves promise on 500 error', function() {
return fetch('/boom').then(function(response) {
assert.equal(response.status, 500)
assert.equal(response.ok, false)
return response.text()
}).then(function(body) {
assert.equal(body, 'boom')
Expand Down Expand Up @@ -149,6 +150,7 @@ suite('Response', function() {
test('populates response body', function() {
return fetch('/hello').then(function(response) {
assert.equal(response.status, 200)
assert.equal(response.ok, true)
return response.text()
}).then(function(body) {
assert.equal(body, 'hi')
Expand Down Expand Up @@ -455,6 +457,7 @@ suite('Atomic HTTP redirect handling', function() {
test('handles 301 redirect response', function() {
return fetch('/redirect/301').then(function(response) {
assert.equal(response.status, 200)
assert.equal(response.ok, true)
assert.match(response.url, /\/hello/)
return response.text()
}).then(function(body) {
Expand All @@ -465,6 +468,7 @@ suite('Atomic HTTP redirect handling', function() {
test('handles 302 redirect response', function() {
return fetch('/redirect/302').then(function(response) {
assert.equal(response.status, 200)
assert.equal(response.ok, true)
assert.match(response.url, /\/hello/)
return response.text()
}).then(function(body) {
Expand All @@ -475,6 +479,7 @@ suite('Atomic HTTP redirect handling', function() {
test('handles 303 redirect response', function() {
return fetch('/redirect/303').then(function(response) {
assert.equal(response.status, 200)
assert.equal(response.ok, true)
assert.match(response.url, /\/hello/)
return response.text()
}).then(function(body) {
Expand All @@ -485,6 +490,7 @@ suite('Atomic HTTP redirect handling', function() {
test('handles 307 redirect response', function() {
return fetch('/redirect/307').then(function(response) {
assert.equal(response.status, 200)
assert.equal(response.ok, true)
assert.match(response.url, /\/hello/)
return response.text()
}).then(function(body) {
Expand All @@ -497,6 +503,7 @@ suite('Atomic HTTP redirect handling', function() {
;(permanentRedirectSupported ? test : test.skip)('handles 308 redirect response', function() {
return fetch('/redirect/308').then(function(response) {
assert.equal(response.status, 200)
assert.equal(response.ok, true)
assert.match(response.url, /\/hello/)
return response.text()
}).then(function(body) {
Expand Down

0 comments on commit 6057055

Please sign in to comment.