From 96ab9719069d4efec4de943cdae8e2fd857b149e Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Wed, 28 Oct 2015 13:32:31 -0400 Subject: [PATCH] don't parse an undefined message or body --- lib/common/util.js | 4 ++-- test/common/util.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/common/util.js b/lib/common/util.js index 0f69dd61bd9..f4b5775b631 100644 --- a/lib/common/util.js +++ b/lib/common/util.js @@ -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); diff --git a/test/common/util.js b/test/common/util.js index a99a3645b8a..5b630842416 100644 --- a/test/common/util.js +++ b/test/common/util.js @@ -230,6 +230,22 @@ describe('common/util', function() { done(); }); }); + + it('should not parse undefined response', function(done) { + utilOverrides.parseHttpRespMessage = function() { + done(); // Will throw. + }; + + util.handleResp(null, null, null, done); + }); + + it('should not parse undefined body', function(done) { + utilOverrides.parseHttpRespBody = function() { + done(); // Will throw. + }; + + util.handleResp(null, null, null, done); + }); }); describe('parseHttpRespMessage', function() {