Skip to content

Commit ff56bc5

Browse files
committed
Setting code property on HTTPError object to be 'HTTPError' instead of undefined
1 parent fbf9e69 commit ff56bc5

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

source/core/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class HTTPError extends RequestError {
9292
constructor(response: PlainResponse) {
9393
super(`Response code ${response.statusCode} (${response.statusMessage!})`, {}, response.request);
9494
this.name = 'HTTPError';
95+
this.code = 'HTTPError';
9596
}
9697
}
9798

test/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test('properties', withServer, async (t, server, got) => {
2626
t.truthy(error.options);
2727
t.true({}.propertyIsEnumerable.call(error, 'options'));
2828
t.false({}.propertyIsEnumerable.call(error, 'response'));
29-
t.is(error.code, undefined);
29+
t.is(error.code, 'HTTPError');
3030
t.is(error.message, 'Response code 404 (Not Found)');
3131
t.deepEqual(error.options.url, url);
3232
t.is(error.response.headers.connection, 'close');

0 commit comments

Comments
 (0)