Skip to content

Commit

Permalink
feat: add missing error type (#3964)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigioliva authored Dec 19, 2024
1 parent 3eeeeb7 commit 8044a43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/types/errors.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ expectAssignable<errors.BodyTimeoutError>(new errors.BodyTimeoutError())
expectAssignable<'BodyTimeoutError'>(new errors.BodyTimeoutError().name)
expectAssignable<'UND_ERR_BODY_TIMEOUT'>(new errors.BodyTimeoutError().code)

expectAssignable<errors.UndiciError>(new errors.ResponseError('', 0, {}))
expectAssignable<errors.ResponseError>(new errors.ResponseError('', 0, {}))
expectAssignable<'ResponseError'>(new errors.ResponseError('', 0, {}).name)
expectAssignable<'UND_ERR_RESPONSE'>(new errors.ResponseError('', 0, {}).code)
expectAssignable<number>(new errors.ResponseError('', 0, {}).statusCode)
expectAssignable<IncomingHttpHeaders | string[] | null>(new errors.ResponseError('', 0, {}).headers)
expectAssignable<null | Record<string, any> | string>(new errors.ResponseError('', 0, {}).body)

expectAssignable<errors.UndiciError>(new errors.ResponseStatusCodeError())
expectAssignable<errors.ResponseStatusCodeError>(new errors.ResponseStatusCodeError())
expectAssignable<'ResponseStatusCodeError'>(new errors.ResponseStatusCodeError().name)
Expand Down
16 changes: 16 additions & 0 deletions types/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, any> | string
}
)
name: 'ResponseError'
code: 'UND_ERR_RESPONSE'
statusCode: number
body: null | Record<string, any> | string
headers: IncomingHttpHeaders | string[] | null
}

export class ResponseStatusCodeError extends UndiciError {
constructor (
message?: string,
Expand Down

0 comments on commit 8044a43

Please sign in to comment.