From ff56bc586d262ddfb3b5d250a963998827d69b7c Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Tue, 1 Jun 2021 20:29:24 -0500 Subject: [PATCH] Setting code property on HTTPError object to be 'HTTPError' instead of undefined --- source/core/errors.ts | 1 + test/error.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/core/errors.ts b/source/core/errors.ts index c3e61fe95..e7fe7f850 100644 --- a/source/core/errors.ts +++ b/source/core/errors.ts @@ -92,6 +92,7 @@ export class HTTPError extends RequestError { constructor(response: PlainResponse) { super(`Response code ${response.statusCode} (${response.statusMessage!})`, {}, response.request); this.name = 'HTTPError'; + this.code = 'HTTPError'; } } diff --git a/test/error.ts b/test/error.ts index 2fdfc21f4..024e5e744 100644 --- a/test/error.ts +++ b/test/error.ts @@ -26,7 +26,7 @@ test('properties', withServer, async (t, server, got) => { t.truthy(error.options); t.true({}.propertyIsEnumerable.call(error, 'options')); t.false({}.propertyIsEnumerable.call(error, 'response')); - t.is(error.code, undefined); + t.is(error.code, 'HTTPError'); t.is(error.message, 'Response code 404 (Not Found)'); t.deepEqual(error.options.url, url); t.is(error.response.headers.connection, 'close');