aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/common.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-11-02 14:23:26 +0100
committerFlorian Dold <florian@dold.me>2022-11-02 14:23:26 +0100
commit1e6e1a22cdb16975f3a914b2f1be6db0ae1b241d (patch)
treeef3b0bcf0d8c8bf8bd3fd2082b53d450f7a09f11 /packages/taler-wallet-core/src/operations/common.ts
parentfe011321a4b65bc0736634ee2a4d9c7bf0618351 (diff)
downloadwallet-core-1e6e1a22cdb16975f3a914b2f1be6db0ae1b241d.tar.xz
wallet-core: fix exchange management test case, surface exchange update error info in list
Diffstat (limited to 'packages/taler-wallet-core/src/operations/common.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/common.ts44
1 files changed, 34 insertions, 10 deletions
diff --git a/packages/taler-wallet-core/src/operations/common.ts b/packages/taler-wallet-core/src/operations/common.ts
index e29065390..f35556736 100644
--- a/packages/taler-wallet-core/src/operations/common.ts
+++ b/packages/taler-wallet-core/src/operations/common.ts
@@ -28,6 +28,7 @@ import {
ExchangeTosStatus,
j2s,
Logger,
+ OperationErrorInfo,
RefreshReason,
TalerErrorCode,
TalerErrorDetail,
@@ -224,30 +225,37 @@ export async function storeOperationPending(
});
}
-export async function runOperationWithErrorReporting(
+export async function runOperationWithErrorReporting<T1, T2>(
ws: InternalWalletState,
opId: string,
- f: () => Promise<OperationAttemptResult>,
-): Promise<void> {
+ f: () => Promise<OperationAttemptResult<T1, T2>>,
+): Promise<OperationAttemptResult<T1, T2>> {
let maybeError: TalerErrorDetail | undefined;
try {
const resp = await f();
switch (resp.type) {
case OperationAttemptResultType.Error:
- return await storeOperationError(ws, opId, resp.errorDetail);
+ await storeOperationError(ws, opId, resp.errorDetail);
+ return resp;
case OperationAttemptResultType.Finished:
- return await storeOperationFinished(ws, opId);
+ await storeOperationFinished(ws, opId);
+ return resp;
case OperationAttemptResultType.Pending:
- return await storeOperationPending(ws, opId);
+ await storeOperationPending(ws, opId);
+ return resp;
case OperationAttemptResultType.Longpoll:
- break;
+ return resp;
}
} catch (e) {
if (e instanceof TalerError) {
logger.warn("operation processed resulted in error");
logger.warn(`error was: ${j2s(e.errorDetail)}`);
maybeError = e.errorDetail;
- return await storeOperationError(ws, opId, maybeError!);
+ await storeOperationError(ws, opId, maybeError!);
+ return {
+ type: OperationAttemptResultType.Error,
+ errorDetail: e.errorDetail,
+ };
} else if (e instanceof Error) {
// This is a bug, as we expect pending operations to always
// do their own error handling and only throw WALLET_PENDING_OPERATION_FAILED
@@ -261,7 +269,11 @@ export async function runOperationWithErrorReporting(
},
`unexpected exception (message: ${e.message})`,
);
- return await storeOperationError(ws, opId, maybeError);
+ await storeOperationError(ws, opId, maybeError);
+ return {
+ type: OperationAttemptResultType.Error,
+ errorDetail: maybeError,
+ };
} else {
logger.error("Uncaught exception, value is not even an error.");
maybeError = makeErrorDetail(
@@ -269,7 +281,11 @@ export async function runOperationWithErrorReporting(
{},
`unexpected exception (not even an error)`,
);
- return await storeOperationError(ws, opId, maybeError);
+ await storeOperationError(ws, opId, maybeError);
+ return {
+ type: OperationAttemptResultType.Error,
+ errorDetail: maybeError,
+ };
}
}
}
@@ -357,7 +373,13 @@ export function getExchangeTosStatus(
export function makeExchangeListItem(
r: ExchangeRecord,
exchangeDetails: ExchangeDetailsRecord | undefined,
+ lastError: TalerErrorDetail | undefined,
): ExchangeListItem {
+ const lastUpdateErrorInfo: OperationErrorInfo | undefined = lastError
+ ? {
+ error: lastError,
+ }
+ : undefined;
if (!exchangeDetails) {
return {
exchangeBaseUrl: r.baseUrl,
@@ -367,6 +389,7 @@ export function makeExchangeListItem(
exchangeStatus: ExchangeEntryStatus.Unknown,
permanent: r.permanent,
ageRestrictionOptions: [],
+ lastUpdateErrorInfo,
};
}
let exchangeStatus;
@@ -381,5 +404,6 @@ export function makeExchangeListItem(
ageRestrictionOptions: exchangeDetails.ageMask
? AgeRestriction.getAgeGroupsFromMask(exchangeDetails.ageMask)
: [],
+ lastUpdateErrorInfo,
};
}