Skip to content

Commit

Permalink
fix: update error definitions (nodejs#2112)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfilatov authored and metcoder95 committed Jul 21, 2023
1 parent 095e32a commit 4e6e54e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions test/types/errors.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { expectAssignable } from 'tsd'
import { errors } from '../..'
import Client from '../../types/client'
import { IncomingHttpHeaders } from "../../types/header";

expectAssignable<errors.UndiciError>(new errors.UndiciError())
expectAssignable<string>(new errors.UndiciError().name)
expectAssignable<string>(new errors.UndiciError().code)

expectAssignable<errors.UndiciError>(new errors.ConnectTimeoutError())
expectAssignable<errors.ConnectTimeoutError>(new errors.ConnectTimeoutError())
Expand All @@ -28,6 +31,10 @@ expectAssignable<errors.UndiciError>(new errors.ResponseStatusCodeError())
expectAssignable<errors.ResponseStatusCodeError>(new errors.ResponseStatusCodeError())
expectAssignable<'ResponseStatusCodeError'>(new errors.ResponseStatusCodeError().name)
expectAssignable<'UND_ERR_RESPONSE_STATUS_CODE'>(new errors.ResponseStatusCodeError().code)
expectAssignable<number>(new errors.ResponseStatusCodeError().status)
expectAssignable<number>(new errors.ResponseStatusCodeError().statusCode)
expectAssignable<IncomingHttpHeaders | string[] | null>(new errors.ResponseStatusCodeError().headers)
expectAssignable<null | Record<string, any> | string>(new errors.ResponseStatusCodeError().body)

expectAssignable<errors.UndiciError>(new errors.InvalidArgumentError())
expectAssignable<errors.InvalidArgumentError>(new errors.InvalidArgumentError())
Expand Down
11 changes: 10 additions & 1 deletion types/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import Client from './client'
export default Errors

declare namespace Errors {
export class UndiciError extends Error { }
export class UndiciError extends Error {
name: string;
code: string;
}

/** Connect timeout error. */
export class ConnectTimeoutError extends UndiciError {
Expand All @@ -31,6 +34,12 @@ declare namespace Errors {
}

export class ResponseStatusCodeError extends UndiciError {
constructor (
message?: string,
statusCode?: number,
headers?: IncomingHttpHeaders | string[] | null,
body?: null | Record<string, any> | string
);
name: 'ResponseStatusCodeError';
code: 'UND_ERR_RESPONSE_STATUS_CODE';
body: null | Record<string, any> | string
Expand Down

0 comments on commit 4e6e54e

Please sign in to comment.