taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit c6968c3c21d70bd76ce50f232650d183fa8cfa6e
parent 39ba26c7623a380c15bf183d25ec8f1fd60b65b6
Author: Sebastian <sebasjm@gmail.com>
Date:   Thu, 19 Oct 2023 02:43:36 -0300

talerhttperror definition, for error in http request

Diffstat:
Mpackages/taler-util/src/errors.ts | 33+++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)

diff --git 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; } + } /**