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');