Browse Source

make response property non enumerable on error

http2
Vsevolod Strukchinsky 9 years ago
parent
commit
dcc7de6815
  1. 5
      index.js
  2. 4
      test/error.js

5
index.js

@ -130,7 +130,10 @@ function asPromise(opts) {
} }
if (err) { if (err) {
err.response = response; Object.defineProperty(err, 'response', {
value: response,
enumerable: false
});
reject(err); reject(err);
return; return;
} }

4
test/error.js

@ -15,12 +15,14 @@ test.before('setup', async t => {
await s.listen(s.port); await s.listen(s.port);
}); });
test('message', async t => { test('properties', async t => {
try { try {
await got(s.url); await got(s.url);
t.fail('Exception was not thrown'); t.fail('Exception was not thrown');
} catch (err) { } catch (err) {
t.ok(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.message, 'Response code 404 (Not Found)');
t.is(err.host, `${s.host}:${s.port}`); t.is(err.host, `${s.host}:${s.port}`);
t.is(err.method, 'GET'); t.is(err.method, 'GET');

Loading…
Cancel
Save