Skip to content

Commit a46cfce

Browse files
committed
Merge pull request #126 from sindresorhus/cleanup-stdErr
Remove undefined code in errors
2 parents 1f5658d + cf54459 commit a46cfce

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,12 @@ helpers.forEach(function (el) {
326326
});
327327

328328
function stdError(error, opts) {
329+
if (error.code !== undefined) {
330+
this.code = error.code;
331+
}
332+
329333
objectAssign(this, {
330334
message: error.message,
331-
code: error.code,
332335
host: opts.host,
333336
hostname: opts.hostname,
334337
method: opts.method,

test/error.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ test('properties', async t => {
2323
t.ok(err);
2424
t.ok(err.response);
2525
t.ok(!err.propertyIsEnumerable('response'));
26+
t.ok(!err.hasOwnProperty('code'));
2627
t.is(err.message, 'Response code 404 (Not Found)');
2728
t.is(err.host, `${s.host}:${s.port}`);
2829
t.is(err.method, 'GET');

0 commit comments

Comments
 (0)