From 5056da6548d5880211abd3e1cdacd92134e40dab Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 1 Sep 2020 18:00:46 +0530 Subject: test error handling --- .../taler-wallet-core/src/operations/withdraw.ts | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts') diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 270735fcb..3977ba121 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -59,6 +59,7 @@ import { import { readSuccessResponseJsonOrThrow } from "../util/http"; import { URL } from "../util/url"; import { TalerErrorCode } from "../TalerErrorCode"; +import { encodeCrock } from "../crypto/talerCrypto"; const logger = new Logger("withdraw.ts"); @@ -558,9 +559,6 @@ async function incrementWithdrawalRetry( if (!wsr) { return; } - if (!wsr.retryInfo) { - return; - } wsr.retryInfo.retryCounter++; updateRetryInfoTimeout(wsr.retryInfo); wsr.lastError = err; @@ -647,12 +645,13 @@ async function processWithdrawGroupImpl( let numFinished = 0; let finishedForFirstTime = false; + let errorsPerCoin: Record = {}; await ws.db.runWithWriteTransaction( [Stores.coins, Stores.withdrawalGroups, Stores.reserves, Stores.planchets], async (tx) => { - const ws = await tx.get(Stores.withdrawalGroups, withdrawalGroupId); - if (!ws) { + const wg = await tx.get(Stores.withdrawalGroups, withdrawalGroupId); + if (!wg) { return; } @@ -662,22 +661,29 @@ async function processWithdrawGroupImpl( if (x.withdrawalDone) { numFinished++; } + if (x.lastError) { + errorsPerCoin[x.coinIdx] = x.lastError; + } }); - - if (ws.timestampFinish === undefined && numFinished == numTotalCoins) { + logger.trace(`now withdrawn ${numFinished} of ${numTotalCoins} coins`); + if (wg.timestampFinish === undefined && numFinished === numTotalCoins) { finishedForFirstTime = true; - ws.timestampFinish = getTimestampNow(); - ws.lastError = undefined; - ws.retryInfo = initRetryInfo(false); + wg.timestampFinish = getTimestampNow(); + wg.lastError = undefined; + wg.retryInfo = initRetryInfo(false); } - await tx.put(Stores.withdrawalGroups, ws); + + await tx.put(Stores.withdrawalGroups, wg); }, ); if (numFinished != numTotalCoins) { - // FIXME: aggregate individual problems into the big error message here. - throw Error( + throw OperationFailedError.fromCode( + TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE, `withdrawal did not finish (${numFinished} / ${numTotalCoins} coins withdrawn)`, + { + errorsPerCoin, + }, ); } -- cgit v1.2.3