diff --git a/index.js b/index.js index d638de2..c9c2bdf 100644 --- a/index.js +++ b/index.js @@ -130,7 +130,10 @@ function asPromise(opts) { } if (err) { - err.response = response; + Object.defineProperty(err, 'response', { + value: response, + enumerable: false + }); reject(err); return; } diff --git a/test/error.js b/test/error.js index 68b8d70..a6b1783 100644 --- a/test/error.js +++ b/test/error.js @@ -15,12 +15,14 @@ test.before('setup', async t => { await s.listen(s.port); }); -test('message', async t => { +test('properties', async t => { try { await got(s.url); t.fail('Exception was not thrown'); } catch (err) { t.ok(err); + t.ok(err.response); + t.ok(!err.propertyIsEnumerable('response')); t.is(err.message, 'Response code 404 (Not Found)'); t.is(err.host, `${s.host}:${s.port}`); t.is(err.method, 'GET');