diff --git a/lib/response.js b/lib/response.js index 53a70cc..c116e8e 100644 --- a/lib/response.js +++ b/lib/response.js @@ -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; } diff --git a/test/test.js b/test/test.js index 344c63e..5b365fb 100644 --- a/test/test.js +++ b/test/test.js @@ -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; }); });