wallet-core: report refresh errors properly

This commit is contained in:
Florian Dold 2023-02-21 01:48:12 +01:00
parent e56d3ba8eb
commit 4762018dc1
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
3 changed files with 677 additions and 1 deletions

View File

@ -122,6 +122,13 @@ export interface DetailsMap {
[TalerErrorCode.WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE]: { [TalerErrorCode.WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE]: {
insufficientBalanceDetails: PayPeerInsufficientBalanceDetails; insufficientBalanceDetails: PayPeerInsufficientBalanceDetails;
}; };
[TalerErrorCode.WALLET_REFRESH_GROUP_INCOMPLETE]: {
numErrors: number;
/**
* Errors, can be truncated.
*/
errors: TalerErrorDetail[];
};
} }
type ErrBody<Y> = Y extends keyof DetailsMap ? DetailsMap[Y] : empty; type ErrBody<Y> = Y extends keyof DetailsMap ? DetailsMap[Y] : empty;

File diff suppressed because it is too large Load Diff

View File

@ -36,14 +36,18 @@ import {
ExchangeProtocolVersion, ExchangeProtocolVersion,
ExchangeRefreshRevealRequest, ExchangeRefreshRevealRequest,
fnutil, fnutil,
getErrorDetailFromException,
getRandomBytes, getRandomBytes,
HashCodeString, HashCodeString,
HttpStatusCode, HttpStatusCode,
j2s, j2s,
Logger, Logger,
makeErrorDetail,
NotificationType, NotificationType,
RefreshGroupId, RefreshGroupId,
RefreshReason, RefreshReason,
TalerErrorCode,
TalerErrorDetail,
TalerProtocolTimestamp, TalerProtocolTimestamp,
URL, URL,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
@ -755,13 +759,18 @@ export async function processRefreshGroup(
} }
// Process refresh sessions of the group in parallel. // Process refresh sessions of the group in parallel.
logger.trace("processing refresh sessions for old coins"); logger.trace("processing refresh sessions for old coins");
let errors: TalerErrorDetail[] = [];
let inShutdown = false;
const ps = refreshGroup.oldCoinPubs.map((x, i) => const ps = refreshGroup.oldCoinPubs.map((x, i) =>
processRefreshSession(ws, refreshGroupId, i).catch((x) => { processRefreshSession(ws, refreshGroupId, i).catch((x) => {
if (x instanceof CryptoApiStoppedError) { if (x instanceof CryptoApiStoppedError) {
inShutdown = true;
logger.info( logger.info(
"crypto API stopped while processing refresh group, probably the wallet is currently shutting down.", "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("process refresh session got exception (TalerError)");
logger.warn(`exc ${x}`); logger.warn(`exc ${x}`);
logger.warn(`exc stack ${x.stack}`); logger.warn(`exc stack ${x.stack}`);
@ -771,6 +780,7 @@ export async function processRefreshGroup(
logger.warn(`exc ${x}`); logger.warn(`exc ${x}`);
logger.warn(`exc stack ${x.stack}`); logger.warn(`exc stack ${x.stack}`);
} }
errors.push(getErrorDetailFromException(x));
}), }),
); );
try { try {
@ -781,6 +791,25 @@ export async function processRefreshGroup(
logger.warn("process refresh sessions got exception"); logger.warn("process refresh sessions got exception");
logger.warn(`exception: ${e}`); 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 { return {
type: OperationAttemptResultType.Finished, type: OperationAttemptResultType.Finished,
result: undefined, result: undefined,