minor format fix and comments

This commit is contained in:
David Frank 2016-09-24 17:12:18 +08:00
parent 95b58936b8
commit e926483448
3 changed files with 7 additions and 5 deletions

View File

@ -39,7 +39,11 @@ function Body(body, opts) {
*/ */
Body.prototype.json = function() { Body.prototype.json = function() {
if (this.status === 204) return Body.Promise.resolve({}); // for 204 No Content response, buffer will be empty, parsing it will throw error
if (this.status === 204) {
return Body.Promise.resolve({});
}
return this._decode().then(function(buffer) { return this._decode().then(function(buffer) {
return JSON.parse(buffer.toString()); return JSON.parse(buffer.toString());
}); });

View File

@ -1,3 +1,4 @@
var http = require('http'); var http = require('http');
var parse = require('url').parse; var parse = require('url').parse;
var zlib = require('zlib'); var zlib = require('zlib');

View File

@ -1,3 +1,4 @@
// test tools // test tools
var chai = require('chai'); var chai = require('chai');
var cap = require('chai-as-promised'); var cap = require('chai-as-promised');
@ -1391,7 +1392,6 @@ describe('node-fetch', function() {
}); });
}); });
it('should support json() method in Request constructor', function() { it('should support json() method in Request constructor', function() {
url = base; url = base;
var req = new Request(url, { var req = new Request(url, {
@ -1403,7 +1403,6 @@ describe('node-fetch', function() {
}); });
}); });
it('should support buffer() method in Request constructor', function() { it('should support buffer() method in Request constructor', function() {
url = base; url = base;
var req = new Request(url, { var req = new Request(url, {
@ -1462,7 +1461,6 @@ describe('node-fetch', function() {
expect(body).to.have.property('buffer'); expect(body).to.have.property('buffer');
}); });
it('should create custom FetchError', function() { it('should create custom FetchError', function() {
var systemError = new Error('system'); var systemError = new Error('system');
systemError.code = 'ESOMEERROR'; systemError.code = 'ESOMEERROR';
@ -1477,7 +1475,6 @@ describe('node-fetch', function() {
expect(err.errno).to.equal('ESOMEERROR'); expect(err.errno).to.equal('ESOMEERROR');
}); });
it('should support https request', function() { it('should support https request', function() {
this.timeout(5000); this.timeout(5000);
url = 'https://github.com/'; url = 'https://github.com/';