From c6968c3c21d70bd76ce50f232650d183fa8cfa6e Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 19 Oct 2023 02:43:36 -0300 Subject: talerhttperror definition, for error in http request --- packages/taler-util/src/errors.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'packages/taler-util/src/errors.ts') 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; -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; }; - [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 +} + +export type TalerHttpError = TalerHttpErrorsDetails[keyof TalerHttpErrorsDetails] + export class TalerError extends Error { errorDetail: TalerErrorDetail & T; private constructor(d: TalerErrorDetail & T) { @@ -239,6 +243,7 @@ export class TalerError extends Error { ): this is TalerError { return this.errorDetail.code === code; } + } /** -- cgit v1.2.3