From 8a64d887febf792ae097a5282292e1e86f199ef8 Mon Sep 17 00:00:00 2001 From: Gianluigi Oliva Date: Wed, 18 Dec 2024 23:25:15 +0100 Subject: [PATCH] feat: add missing error type --- test/types/errors.test-d.ts | 8 ++++++++ types/errors.d.ts | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/test/types/errors.test-d.ts b/test/types/errors.test-d.ts index df04775cb02..d1c59a366b9 100644 --- a/test/types/errors.test-d.ts +++ b/test/types/errors.test-d.ts @@ -27,6 +27,14 @@ expectAssignable(new errors.BodyTimeoutError()) expectAssignable<'BodyTimeoutError'>(new errors.BodyTimeoutError().name) expectAssignable<'UND_ERR_BODY_TIMEOUT'>(new errors.BodyTimeoutError().code) +expectAssignable(new errors.ResponseError('', 0, {})) +expectAssignable(new errors.ResponseError('', 0, {})) +expectAssignable<'ResponseError'>(new errors.ResponseError('', 0, {}).name) +expectAssignable<'UND_ERR_RESPONSE'>(new errors.ResponseError('', 0, {}).code) +expectAssignable(new errors.ResponseError('', 0, {}).statusCode) +expectAssignable(new errors.ResponseError('', 0, {}).headers) +expectAssignable | string>(new errors.ResponseError('', 0, {}).body) + expectAssignable(new errors.ResponseStatusCodeError()) expectAssignable(new errors.ResponseStatusCodeError()) expectAssignable<'ResponseStatusCodeError'>(new errors.ResponseStatusCodeError().name) diff --git a/types/errors.d.ts b/types/errors.d.ts index fdf806e90a1..387420db040 100644 --- a/types/errors.d.ts +++ b/types/errors.d.ts @@ -33,6 +33,22 @@ declare namespace Errors { code: 'UND_ERR_BODY_TIMEOUT' } + export class ResponseError extends UndiciError { + constructor ( + message: string, + code: number, + options: { + headers?: IncomingHttpHeaders | string[] | null, + body?: null | Record | string + } + ) + name: 'ResponseError' + code: 'UND_ERR_RESPONSE' + statusCode: number + body: null | Record | string + headers: IncomingHttpHeaders | string[] | null + } + export class ResponseStatusCodeError extends UndiciError { constructor ( message?: string,