diff --git a/test/types/errors.test-d.ts b/test/types/errors.test-d.ts index 53b544dfcd1..8708519504b 100644 --- a/test/types/errors.test-d.ts +++ b/test/types/errors.test-d.ts @@ -4,29 +4,44 @@ import Client from '../../types/client' expectAssignable(new errors.UndiciError()) +expectAssignable(new errors.ConnectTimeoutError()) +expectAssignable(new errors.ConnectTimeoutError()) +expectAssignable<'ConnectTimeoutError'>(new errors.ConnectTimeoutError().name) +expectAssignable<'UND_ERR_CONNECT_TIMEOUT'>(new errors.ConnectTimeoutError().code) + expectAssignable(new errors.HeadersTimeoutError()) expectAssignable(new errors.HeadersTimeoutError()) expectAssignable<'HeadersTimeoutError'>(new errors.HeadersTimeoutError().name) expectAssignable<'UND_ERR_HEADERS_TIMEOUT'>(new errors.HeadersTimeoutError().code) +expectAssignable(new errors.HeadersOverflowError()) +expectAssignable(new errors.HeadersOverflowError()) +expectAssignable<'HeadersOverflowError'>(new errors.HeadersOverflowError().name) +expectAssignable<'UND_ERR_HEADERS_OVERFLOW'>(new errors.HeadersOverflowError().code) + expectAssignable(new errors.BodyTimeoutError()) expectAssignable(new errors.BodyTimeoutError()) expectAssignable<'BodyTimeoutError'>(new errors.BodyTimeoutError().name) expectAssignable<'UND_ERR_BODY_TIMEOUT'>(new errors.BodyTimeoutError().code) -expectAssignable(new errors.SocketTimeoutError()) -expectAssignable(new errors.SocketTimeoutError()) -expectAssignable<'SocketTimeoutError'>(new errors.SocketTimeoutError().name) -expectAssignable<'UND_ERR_SOCKET_TIMEOUT'>(new errors.SocketTimeoutError().code) +expectAssignable(new errors.ResponseStatusCodeError()) +expectAssignable(new errors.ResponseStatusCodeError()) +expectAssignable<'ResponseStatusCodeError'>(new errors.ResponseStatusCodeError().name) +expectAssignable<'UND_ERR_RESPONSE_STATUS_CODE'>(new errors.ResponseStatusCodeError().code) -expectAssignable(new errors.InvalidReturnError()) -expectAssignable(new errors.InvalidReturnError()) -expectAssignable<'InvalidReturnError'>(new errors.InvalidReturnError().name) -expectAssignable<'UND_ERR_INVALID_RETURN_VALUE'>(new errors.InvalidReturnError().code) +expectAssignable(new errors.InvalidArgumentError()) +expectAssignable(new errors.InvalidArgumentError()) +expectAssignable<'InvalidArgumentError'>(new errors.InvalidArgumentError().name) +expectAssignable<'UND_ERR_INVALID_ARG'>(new errors.InvalidArgumentError().code) + +expectAssignable(new errors.InvalidReturnValueError()) +expectAssignable(new errors.InvalidReturnValueError()) +expectAssignable<'InvalidReturnValueError'>(new errors.InvalidReturnValueError().name) +expectAssignable<'UND_ERR_INVALID_RETURN_VALUE'>(new errors.InvalidReturnValueError().code) expectAssignable(new errors.RequestAbortedError()) expectAssignable(new errors.RequestAbortedError()) -expectAssignable<'RequestAbortedError'>(new errors.RequestAbortedError().name) +expectAssignable<'AbortError'>(new errors.RequestAbortedError().name) expectAssignable<'UND_ERR_ABORTED'>(new errors.RequestAbortedError().code) expectAssignable(new errors.InformationalError()) @@ -39,6 +54,11 @@ expectAssignable(new errors.RequestCon expectAssignable<'RequestContentLengthMismatchError'>(new errors.RequestContentLengthMismatchError().name) expectAssignable<'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'>(new errors.RequestContentLengthMismatchError().code) +expectAssignable(new errors.ResponseContentLengthMismatchError()) +expectAssignable(new errors.ResponseContentLengthMismatchError()) +expectAssignable<'ResponseContentLengthMismatchError'>(new errors.ResponseContentLengthMismatchError().name) +expectAssignable<'UND_ERR_RES_CONTENT_LENGTH_MISMATCH'>(new errors.ResponseContentLengthMismatchError().code) + expectAssignable(new errors.ClientDestroyedError()) expectAssignable(new errors.ClientDestroyedError()) expectAssignable<'ClientDestroyedError'>(new errors.ClientDestroyedError().name) @@ -60,15 +80,29 @@ expectAssignable(new errors.NotSupportedError()) expectAssignable<'NotSupportedError'>(new errors.NotSupportedError().name) expectAssignable<'UND_ERR_NOT_SUPPORTED'>(new errors.NotSupportedError().code) +expectAssignable(new errors.BalancedPoolMissingUpstreamError()) +expectAssignable(new errors.BalancedPoolMissingUpstreamError()) +expectAssignable<'MissingUpstreamError'>(new errors.BalancedPoolMissingUpstreamError().name) +expectAssignable<'UND_ERR_BPL_MISSING_UPSTREAM'>(new errors.BalancedPoolMissingUpstreamError().code) + +expectAssignable(new errors.HTTPParserError()) +expectAssignable(new errors.HTTPParserError()) +expectAssignable<'HTTPParserError'>(new errors.HTTPParserError().name) + +expectAssignable(new errors.ResponseExceededMaxSizeError()) +expectAssignable(new errors.ResponseExceededMaxSizeError()) +expectAssignable<'ResponseExceededMaxSizeError'>(new errors.ResponseExceededMaxSizeError().name) +expectAssignable<'UND_ERR_RES_EXCEEDED_MAX_SIZE'>(new errors.ResponseExceededMaxSizeError().code) + { // @ts-ignore - function f (): errors.HeadersTimeoutError | errors.SocketTimeoutError { return } + function f (): errors.HeadersTimeoutError | errors.ConnectTimeoutError { return } const e = f() if (e.code === 'UND_ERR_HEADERS_TIMEOUT') { expectAssignable(e) - } else if (e.code === 'UND_ERR_SOCKET_TIMEOUT') { - expectAssignable(e) + } else if (e.code === 'UND_ERR_CONNECT_TIMEOUT') { + expectAssignable(e) } } diff --git a/types/errors.d.ts b/types/errors.d.ts index c4ef4b6f633..79f820ddd29 100644 --- a/types/errors.d.ts +++ b/types/errors.d.ts @@ -6,12 +6,24 @@ export default Errors declare namespace Errors { export class UndiciError extends Error { } + /** Connect timeout error. */ + export class ConnectTimeoutError extends UndiciError { + name: 'ConnectTimeoutError'; + code: 'UND_ERR_CONNECT_TIMEOUT'; + } + /** A header exceeds the `headersTimeout` option. */ export class HeadersTimeoutError extends UndiciError { name: 'HeadersTimeoutError'; code: 'UND_ERR_HEADERS_TIMEOUT'; } + /** Headers overflow error. */ + export class HeadersOverflowError extends UndiciError { + name: 'HeadersOverflowError' + code: 'UND_ERR_HEADERS_OVERFLOW' + } + /** A body exceeds the `bodyTimeout` option. */ export class BodyTimeoutError extends UndiciError { name: 'BodyTimeoutError'; @@ -27,12 +39,6 @@ declare namespace Errors { headers: IncomingHttpHeaders | string[] | null; } - /** A socket exceeds the `socketTimeout` option. */ - export class SocketTimeoutError extends UndiciError { - name: 'SocketTimeoutError'; - code: 'UND_ERR_SOCKET_TIMEOUT'; - } - /** Passed an invalid argument. */ export class InvalidArgumentError extends UndiciError { name: 'InvalidArgumentError'; @@ -40,14 +46,14 @@ declare namespace Errors { } /** Returned an invalid value. */ - export class InvalidReturnError extends UndiciError { - name: 'InvalidReturnError'; + export class InvalidReturnValueError extends UndiciError { + name: 'InvalidReturnValueError'; code: 'UND_ERR_INVALID_RETURN_VALUE'; } /** The request has been aborted by the user. */ export class RequestAbortedError extends UndiciError { - name: 'RequestAbortedError'; + name: 'AbortError'; code: 'UND_ERR_ABORTED'; } @@ -57,12 +63,18 @@ declare namespace Errors { code: 'UND_ERR_INFO'; } - /** Body does not match content-length header. */ + /** Request body length does not match content-length header. */ export class RequestContentLengthMismatchError extends UndiciError { name: 'RequestContentLengthMismatchError'; code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'; } + /** Response body length does not match content-length header. */ + export class ResponseContentLengthMismatchError extends UndiciError { + name: 'ResponseContentLengthMismatchError'; + code: 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH'; + } + /** Trying to use a destroyed client. */ export class ClientDestroyedError extends UndiciError { name: 'ClientDestroyedError'; @@ -88,7 +100,18 @@ declare namespace Errors { code: 'UND_ERR_NOT_SUPPORTED'; } - /** The response exceed the length allowed */ + /** No upstream has been added to the BalancedPool. */ + export class BalancedPoolMissingUpstreamError extends UndiciError { + name: 'MissingUpstreamError'; + code: 'UND_ERR_BPL_MISSING_UPSTREAM'; + } + + export class HTTPParserError extends UndiciError { + name: 'HTTPParserError'; + code: string; + } + + /** The response exceed the length allowed. */ export class ResponseExceededMaxSizeError extends UndiciError { name: 'ResponseExceededMaxSizeError'; code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE';