diff options
-rw-r--r-- | packages/taler-util/src/errors.ts | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/packages/taler-util/src/errors.ts b/packages/taler-util/src/errors.ts index dcdf56c39..f17f7db6a 100644 --- a/packages/taler-util/src/errors.ts +++ b/packages/taler-util/src/errors.ts @@ -34,19 +34,6 @@ import { type empty = Record<string, never>; -export interface HttpErrors { - // timeout - [TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT]: empty; - // throttled - [TalerErrorCode.WALLET_HTTP_REQUEST_THROTTLED]: empty; - // parsing - [TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE]: empty; - // network - [TalerErrorCode.WALLET_NETWORK_ERROR]: empty; - // everything else - [TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR]: empty; -} - export interface DetailsMap { [TalerErrorCode.WALLET_PENDING_OPERATION_FAILED]: { innerError: TalerErrorDetail; @@ -102,7 +89,11 @@ export interface DetailsMap { requestMethod: string; throttleStats: Record<string, unknown>; }; - [TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT]: empty; + [TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT]: { + requestUrl: string; + requestMethod: string; + timeoutMs: number; + }; [TalerErrorCode.WALLET_NETWORK_ERROR]: { requestUrl: string; requestMethod: string; @@ -205,6 +196,19 @@ export class TalerProtocolViolationError extends Error { } } +// compute a subset of TalerError, just for http request +type HttpErrors = TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT + | TalerErrorCode.WALLET_HTTP_REQUEST_THROTTLED + | TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE + | TalerErrorCode.WALLET_NETWORK_ERROR + | TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR; + +type TalerHttpErrorsDetails = { + [code in HttpErrors]: TalerError<DetailsMap[code]> +} + +export type TalerHttpError = TalerHttpErrorsDetails[keyof TalerHttpErrorsDetails] + export class TalerError<T = any> extends Error { errorDetail: TalerErrorDetail & T; private constructor(d: TalerErrorDetail & T) { @@ -239,6 +243,7 @@ export class TalerError<T = any> extends Error { ): this is TalerError<DetailsMap[C]> { return this.errorDetail.code === code; } + } /** |