From 859d5c56c7a5b26e741254d6d1e9c5731a787ae1 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 8 Apr 2024 22:29:51 +0200 Subject: wallet-core: support cancellation for getWithdrawalDetailsForAmount --- packages/taler-util/src/errors.ts | 8 ++++++++ packages/taler-util/src/taler-error-codes.ts | 8 ++++++++ packages/taler-util/src/wallet-types.ts | 13 +++++++++++++ 3 files changed, 29 insertions(+) (limited to 'packages/taler-util') diff --git a/packages/taler-util/src/errors.ts b/packages/taler-util/src/errors.ts index 11f01a3fe..4dea7e1b6 100644 --- a/packages/taler-util/src/errors.ts +++ b/packages/taler-util/src/errors.ts @@ -25,6 +25,7 @@ */ import { AbsoluteTime, + CancellationToken, PaymentInsufficientBalanceDetails, TalerErrorCode, TalerErrorDetail, @@ -285,6 +286,13 @@ export function getErrorDetailFromException(e: any): TalerErrorDetail { if (e instanceof TalerError) { return e.errorDetail; } + if (e instanceof CancellationToken.CancellationError) { + const err = makeErrorDetail( + TalerErrorCode.WALLET_CORE_REQUEST_CANCELLED, + {}, + ); + return err; + } if (e instanceof Error) { const err = makeErrorDetail( TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION, diff --git a/packages/taler-util/src/taler-error-codes.ts b/packages/taler-util/src/taler-error-codes.ts index addb1b047..c3c008a1c 100644 --- a/packages/taler-util/src/taler-error-codes.ts +++ b/packages/taler-util/src/taler-error-codes.ts @@ -3944,6 +3944,14 @@ export enum TalerErrorCode { WALLET_TALER_URI_MALFORMED = 7035, + /** + * A wallet-core request was cancelled and thus can't provide a response. + * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). + * (A value of 0 indicates that the error is generated client-side). + */ + WALLET_CORE_REQUEST_CANCELLED = 7036, + + /** * We encountered a timeout with our payment backend. * Returned with an HTTP status code of #MHD_HTTP_GATEWAY_TIMEOUT (504). diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 34d91d3d6..fa0f385b7 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -1857,6 +1857,19 @@ export interface GetWithdrawalDetailsForAmountRequest { exchangeBaseUrl: string; amount: AmountString; restrictAge?: number; + + /** + * ID provided by the client to cancel the request. + * + * If the same request is made again with the same clientCancellationId, + * all previous requests are cancelled. + * + * The cancelled request will receive an error response with + * an error code that indicates the cancellation. + * + * The cancellation is best-effort, responses might still arrive. + */ + clientCancellationId?: string; } export interface AcceptBankIntegratedWithdrawalRequest { -- cgit v1.2.3