From cf544592571f3fc944a8a1e74e468e2fe378e176 Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Sun, 1 Nov 2015 13:58:28 +0500 Subject: [PATCH] remove undefined code in errors --- index.js | 5 ++++- test/error.js | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c9c2bdf..880cccb 100644 --- a/index.js +++ b/index.js @@ -326,9 +326,12 @@ helpers.forEach(function (el) { }); function stdError(error, opts) { + if (error.code !== undefined) { + this.code = error.code; + } + objectAssign(this, { message: error.message, - code: error.code, host: opts.host, hostname: opts.hostname, method: opts.method, diff --git a/test/error.js b/test/error.js index a6b1783..87c41c3 100644 --- a/test/error.js +++ b/test/error.js @@ -23,6 +23,7 @@ test('properties', async t => { t.ok(err); t.ok(err.response); t.ok(!err.propertyIsEnumerable('response')); + t.ok(!err.hasOwnProperty('code')); t.is(err.message, 'Response code 404 (Not Found)'); t.is(err.host, `${s.host}:${s.port}`); t.is(err.method, 'GET');