From bdc1bfb2b849bbb914c20520e12357df92be1e58 Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Tue, 28 Jul 2015 19:56:18 +0500 Subject: [PATCH] Do not assign to undefined response --- index.js | 4 +++- test/test-helpers.js | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 8024a38..dbe426c 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,9 @@ function asCallback(opts, cb) { function asPromise(opts) { return new PinkiePromise(function (resolve, reject) { asCallback(opts, function (err, data, response) { - response.body = data; + if (response) { + response.body = data; + } if (err) { err.response = response; diff --git a/test/test-helpers.js b/test/test-helpers.js index 710e986..63849a4 100644 --- a/test/test-helpers.js +++ b/test/test-helpers.js @@ -28,7 +28,7 @@ test('callback mode', function (t) { }); test('promise mode', function (t) { - t.plan(2); + t.plan(3); got.get(s.url) .then(function (res) { @@ -39,6 +39,11 @@ test('promise mode', function (t) { .catch(function (err) { t.equal(err.response.body, 'not found'); }); + + got.get('.com') + .catch(function (err) { + t.ok(err); + }); }); test('cleanup', function (t) {