Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add missing error type #3964

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What API is emitting this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is in the description. The new responseError interceptor


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