From be41ebf19a0f0446294e6239ca11e0f702b219f3 Mon Sep 17 00:00:00 2001 From: Max Beatty Date: Thu, 6 Jun 2024 23:00:47 -0700 Subject: [PATCH] add missing error classes to types --- lib/handler/retry-handler.js | 6 +- types/errors.d.ts | 105 +++++++++++++++++++++-------------- 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/lib/handler/retry-handler.js b/lib/handler/retry-handler.js index fcd9f0df513..f3456bc4ec9 100644 --- a/lib/handler/retry-handler.js +++ b/lib/handler/retry-handler.js @@ -70,7 +70,7 @@ class RetryHandler { this.resume = null // Handle possible onConnect duplication - this.handler.onConnect(reason => { + this.handler.onConnect((reason) => { this.aborted = true if (this.abort) { this.abort(reason) @@ -202,7 +202,7 @@ class RetryHandler { this.abort( new RequestRetryError('Content-Range mismatch', statusCode, { headers, - count: this.retryCount + data: { count: this.retryCount } }) ) return false @@ -213,7 +213,7 @@ class RetryHandler { this.abort( new RequestRetryError('ETag mismatch', statusCode, { headers, - count: this.retryCount + data: { count: this.retryCount } }) ) return false diff --git a/types/errors.d.ts b/types/errors.d.ts index 7923ddd9796..2f93d222c1f 100644 --- a/types/errors.d.ts +++ b/types/errors.d.ts @@ -1,7 +1,7 @@ import { IncomingHttpHeaders } from "./header"; -import Client from './client' +import Client from "./client"; -export default Errors +export default Errors; declare namespace Errors { export class UndiciError extends Error { @@ -11,118 +11,139 @@ declare namespace Errors { /** Connect timeout error. */ export class ConnectTimeoutError extends UndiciError { - name: 'ConnectTimeoutError'; - code: 'UND_ERR_CONNECT_TIMEOUT'; + 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'; + name: "HeadersTimeoutError"; + code: "UND_ERR_HEADERS_TIMEOUT"; } /** Headers overflow error. */ export class HeadersOverflowError extends UndiciError { - name: 'HeadersOverflowError' - code: 'UND_ERR_HEADERS_OVERFLOW' + name: "HeadersOverflowError"; + code: "UND_ERR_HEADERS_OVERFLOW"; } /** A body exceeds the `bodyTimeout` option. */ export class BodyTimeoutError extends UndiciError { - name: 'BodyTimeoutError'; - code: 'UND_ERR_BODY_TIMEOUT'; + name: "BodyTimeoutError"; + code: "UND_ERR_BODY_TIMEOUT"; } export class ResponseStatusCodeError extends UndiciError { - constructor ( + constructor( message?: string, statusCode?: number, headers?: IncomingHttpHeaders | string[] | null, body?: null | Record | string ); - name: 'ResponseStatusCodeError'; - code: 'UND_ERR_RESPONSE_STATUS_CODE'; - body: null | Record | string - status: number - statusCode: number + name: "ResponseStatusCodeError"; + code: "UND_ERR_RESPONSE_STATUS_CODE"; + body: null | Record | string; + status: number; + statusCode: number; headers: IncomingHttpHeaders | string[] | null; } /** Passed an invalid argument. */ export class InvalidArgumentError extends UndiciError { - name: 'InvalidArgumentError'; - code: 'UND_ERR_INVALID_ARG'; + name: "InvalidArgumentError"; + code: "UND_ERR_INVALID_ARG"; } /** Returned an invalid value. */ export class InvalidReturnValueError extends UndiciError { - name: 'InvalidReturnValueError'; - code: 'UND_ERR_INVALID_RETURN_VALUE'; + name: "InvalidReturnValueError"; + code: "UND_ERR_INVALID_RETURN_VALUE"; } /** The request has been aborted by the user. */ export class RequestAbortedError extends UndiciError { - name: 'AbortError'; - code: 'UND_ERR_ABORTED'; + name: "AbortError"; + code: "UND_ERR_ABORTED"; } /** Expected error with reason. */ export class InformationalError extends UndiciError { - name: 'InformationalError'; - code: 'UND_ERR_INFO'; + name: "InformationalError"; + code: "UND_ERR_INFO"; } /** Request body length does not match content-length header. */ export class RequestContentLengthMismatchError extends UndiciError { - name: 'RequestContentLengthMismatchError'; - code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'; + 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'; + name: "ResponseContentLengthMismatchError"; + code: "UND_ERR_RES_CONTENT_LENGTH_MISMATCH"; } /** Trying to use a destroyed client. */ export class ClientDestroyedError extends UndiciError { - name: 'ClientDestroyedError'; - code: 'UND_ERR_DESTROYED'; + name: "ClientDestroyedError"; + code: "UND_ERR_DESTROYED"; } /** Trying to use a closed client. */ export class ClientClosedError extends UndiciError { - name: 'ClientClosedError'; - code: 'UND_ERR_CLOSED'; + name: "ClientClosedError"; + code: "UND_ERR_CLOSED"; } /** There is an error with the socket. */ export class SocketError extends UndiciError { - name: 'SocketError'; - code: 'UND_ERR_SOCKET'; - socket: Client.SocketInfo | null + name: "SocketError"; + code: "UND_ERR_SOCKET"; + socket: Client.SocketInfo | null; } /** Encountered unsupported functionality. */ export class NotSupportedError extends UndiciError { - name: 'NotSupportedError'; - code: 'UND_ERR_NOT_SUPPORTED'; + name: "NotSupportedError"; + code: "UND_ERR_NOT_SUPPORTED"; } /** No upstream has been added to the BalancedPool. */ export class BalancedPoolMissingUpstreamError extends UndiciError { - name: 'MissingUpstreamError'; - code: 'UND_ERR_BPL_MISSING_UPSTREAM'; + name: "MissingUpstreamError"; + code: "UND_ERR_BPL_MISSING_UPSTREAM"; } export class HTTPParserError extends UndiciError { - name: 'HTTPParserError'; + name: "HTTPParserError"; code: string; } /** The response exceed the length allowed. */ export class ResponseExceededMaxSizeError extends UndiciError { - name: 'ResponseExceededMaxSizeError'; - code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE'; + name: "ResponseExceededMaxSizeError"; + code: "UND_ERR_RES_EXCEEDED_MAX_SIZE"; + } + + export class RequestRetryError extends UndiciError { + constructor( + message: string, + statusCode: number, + headers?: IncomingHttpHeaders | string[] | null, + body?: null | Record | string + ); + name: "RequestRetryError"; + code: "UND_ERR_REQ_RETRY"; + statusCode: number; + data: { + count: number; + }; + headers: Record; + } + + export class SecureProxyConnectionError extends UndiciError { + name: "SecureProxyConnectionError"; + code: "UND_ERR_PRX_TLS"; } }