taler-typescript-core

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

commit fab7c16b7e39b8086a19e1630ceaea3bf5c90b66
parent 03b41b41bf5c162aac6b626f90a8e2de77fe3c11
Author: Florian Dold <dold@taler.net>
Date:   Thu, 23 Jul 2026 01:36:20 +0200

util: add construction-time timeout to exchange http client

Diffstat:
Mpackages/taler-util/src/http-client/exchange-client.ts | 11+++++++++++
Mpackages/taler-wallet-core/src/wallet.ts | 2++
2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/packages/taler-util/src/http-client/exchange-client.ts b/packages/taler-util/src/http-client/exchange-client.ts @@ -120,6 +120,7 @@ import { AmountJson, Amounts, CancellationToken, + Duration, Logger, LongpollQueue, PaytoHash, @@ -156,6 +157,12 @@ export class TalerExchangeHttpClient { private preventCompression: boolean; private cancelationToken: CancellationToken; private longPollQueue: LongpollQueue; + /** + * Timeout applied to every request made by this client. The client is + * short-lived and constructed per logical operation, so the timeout is set + * once here rather than per call. + */ + private defaultTimeout: Duration | undefined; constructor( readonly baseUrl: string, @@ -165,6 +172,7 @@ export class TalerExchangeHttpClient { preventCompression?: boolean; cancelationToken?: CancellationToken; longPollQueue?: LongpollQueue; + timeout?: Duration; } = {}, ) { this.httpLib = params.httpClient ?? createPlatformHttpLib(); @@ -173,6 +181,7 @@ export class TalerExchangeHttpClient { this.cancelationToken = params.cancelationToken ?? CancellationToken.CONTINUE; this.longPollQueue = params.longPollQueue ?? new LongpollQueue(); + this.defaultTimeout = params.timeout; } static isCompatible(version: string): boolean { @@ -199,6 +208,7 @@ export class TalerExchangeHttpClient { async (timeoutMs) => { url.searchParams.set("timeout_ms", String(timeoutMs)); return this.httpLib.fetch(url.href, { + timeout: this.defaultTimeout, cancellationToken: this.cancelationToken, ...opts, }); @@ -206,6 +216,7 @@ export class TalerExchangeHttpClient { ); } else { return this.httpLib.fetch(url.href, { + timeout: this.defaultTimeout, cancellationToken: this.cancelationToken, ...opts, }); diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts @@ -131,11 +131,13 @@ export interface DbRetryState { export function walletExchangeClient( baseUrl: string, wex: WalletExecutionContext, + timeout?: Duration, ): TalerExchangeHttpClient { return new TalerExchangeHttpClient(baseUrl, { httpClient: wex.http, cancelationToken: wex.cancellationToken, longPollQueue: wex.ws.longpollQueue, + timeout, }); }