Skip to content

Commit 1f5658d

Browse files
committed
Merge pull request #125 from sindresorhus/non-enumerable-response-property
Make response property non enumerable on error
2 parents f100c9d + dcc7de6 commit 1f5658d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ function asPromise(opts) {
130130
}
131131

132132
if (err) {
133-
err.response = response;
133+
Object.defineProperty(err, 'response', {
134+
value: response,
135+
enumerable: false
136+
});
134137
reject(err);
135138
return;
136139
}

test/error.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ test.before('setup', async t => {
1515
await s.listen(s.port);
1616
});
1717

18-
test('message', async t => {
18+
test('properties', async t => {
1919
try {
2020
await got(s.url);
2121
t.fail('Exception was not thrown');
2222
} catch (err) {
2323
t.ok(err);
24+
t.ok(err.response);
25+
t.ok(!err.propertyIsEnumerable('response'));
2426
t.is(err.message, 'Response code 404 (Not Found)');
2527
t.is(err.host, `${s.host}:${s.port}`);
2628
t.is(err.method, 'GET');

0 commit comments

Comments
 (0)