From 4762018dc1612e561fe87fd5ff87e6c7006807c7 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 21 Feb 2023 01:48:12 +0100 Subject: wallet-core: report refresh errors properly --- .../taler-wallet-core/src/operations/refresh.ts | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'packages/taler-wallet-core/src/operations/refresh.ts') diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 2d406ec7d..477a00503 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -36,14 +36,18 @@ import { ExchangeProtocolVersion, ExchangeRefreshRevealRequest, fnutil, + getErrorDetailFromException, getRandomBytes, HashCodeString, HttpStatusCode, j2s, Logger, + makeErrorDetail, NotificationType, RefreshGroupId, RefreshReason, + TalerErrorCode, + TalerErrorDetail, TalerProtocolTimestamp, URL, } from "@gnu-taler/taler-util"; @@ -755,13 +759,18 @@ export async function processRefreshGroup( } // Process refresh sessions of the group in parallel. logger.trace("processing refresh sessions for old coins"); + let errors: TalerErrorDetail[] = []; + let inShutdown = false; const ps = refreshGroup.oldCoinPubs.map((x, i) => processRefreshSession(ws, refreshGroupId, i).catch((x) => { if (x instanceof CryptoApiStoppedError) { + inShutdown = true; logger.info( "crypto API stopped while processing refresh group, probably the wallet is currently shutting down.", ); - } else if (x instanceof TalerError) { + return; + } + if (x instanceof TalerError) { logger.warn("process refresh session got exception (TalerError)"); logger.warn(`exc ${x}`); logger.warn(`exc stack ${x.stack}`); @@ -771,6 +780,7 @@ export async function processRefreshGroup( logger.warn(`exc ${x}`); logger.warn(`exc stack ${x.stack}`); } + errors.push(getErrorDetailFromException(x)); }), ); try { @@ -781,6 +791,25 @@ export async function processRefreshGroup( logger.warn("process refresh sessions got exception"); logger.warn(`exception: ${e}`); } + if (inShutdown) { + return { + type: OperationAttemptResultType.Pending, + result: undefined, + }; + } + if (errors.length > 0) { + return { + type: OperationAttemptResultType.Error, + errorDetail: makeErrorDetail( + TalerErrorCode.WALLET_REFRESH_GROUP_INCOMPLETE, + { + numErrors: errors.length, + errors: errors.slice(0, 5), + }, + ), + }; + } + return { type: OperationAttemptResultType.Finished, result: undefined, -- cgit v1.2.3