Add a convenience `ok` getter on `Response`

This commit is contained in:
Matthew Andrews 2015-01-27 23:41:48 +00:00
parent 4532ad699e
commit ff5eabfdf4
2 changed files with 3 additions and 0 deletions

View File

@ -26,6 +26,7 @@ function Response(body, opts) {
this.body = body;
this.bodyUsed = false;
this.size = opts.size;
this.ok = this.status >= 200 && this.status < 300;
}

View File

@ -232,6 +232,7 @@ describe('node-fetch', function() {
expect(res.statusText).to.equal('Internal Server Error');
return res.text().then(function(result) {
expect(res.bodyUsed).to.be.true;
expect(res.ok).to.be.false;
expect(result).to.be.a('string');
expect(result).to.equal('server error');
});
@ -444,6 +445,7 @@ describe('node-fetch', function() {
};
return fetch(url, opts).then(function(res) {
expect(res.status).to.equal(200);
expect(res.ok).to.be.true;
});
});