Skip to content

Commit

Permalink
don't parse an undefined message or body
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Oct 28, 2015
1 parent f23d3d5 commit d39f06f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ function handleResp(err, resp, body, callback) {
var parsedResp = extend(
true,
{ err: err || null },
util.parseHttpRespMessage(resp),
util.parseHttpRespBody(body)
resp && util.parseHttpRespMessage(resp),
body && util.parseHttpRespBody(body)
);

callback(parsedResp.err, parsedResp.body, parsedResp.resp);
Expand Down
16 changes: 16 additions & 0 deletions test/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ describe('common/util', function() {
done();
});
});

it('should not parse undefined response', function(done) {
util.parseHttpRespMessage = function() {
done(); // Will throw.
};

util.handleResp(null, null, null, done);
});

it('should not parse undefined body', function(done) {
util.parseHttpRespBody = function() {
done(); // Will throw.
};

util.handleResp(null, null, null, done);
});
});

describe('parseHttpRespMessage', function() {
Expand Down

0 comments on commit d39f06f

Please sign in to comment.