Merge pull request #1 from matthew-andrews/ok
Add a convenience `ok` getter on `Response`
This commit is contained in:
commit
4da8497bf5
|
@ -26,6 +26,7 @@ function Response(body, opts) {
|
||||||
this.body = body;
|
this.body = body;
|
||||||
this.bodyUsed = false;
|
this.bodyUsed = false;
|
||||||
this.size = opts.size;
|
this.size = opts.size;
|
||||||
|
this.ok = this.status >= 200 && this.status < 300;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -232,6 +232,7 @@ describe('node-fetch', function() {
|
||||||
expect(res.statusText).to.equal('Internal Server Error');
|
expect(res.statusText).to.equal('Internal Server Error');
|
||||||
return res.text().then(function(result) {
|
return res.text().then(function(result) {
|
||||||
expect(res.bodyUsed).to.be.true;
|
expect(res.bodyUsed).to.be.true;
|
||||||
|
expect(res.ok).to.be.false;
|
||||||
expect(result).to.be.a('string');
|
expect(result).to.be.a('string');
|
||||||
expect(result).to.equal('server error');
|
expect(result).to.equal('server error');
|
||||||
});
|
});
|
||||||
|
@ -444,6 +445,7 @@ describe('node-fetch', function() {
|
||||||
};
|
};
|
||||||
return fetch(url, opts).then(function(res) {
|
return fetch(url, opts).then(function(res) {
|
||||||
expect(res.status).to.equal(200);
|
expect(res.status).to.equal(200);
|
||||||
|
expect(res.ok).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue