summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/common.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/common.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/common.ts86
1 files changed, 33 insertions, 53 deletions
diff --git a/packages/taler-wallet-core/src/operations/common.ts b/packages/taler-wallet-core/src/operations/common.ts
index 620054cae..cc16a4704 100644
--- a/packages/taler-wallet-core/src/operations/common.ts
+++ b/packages/taler-wallet-core/src/operations/common.ts
@@ -433,25 +433,25 @@ async function storePendingTaskFinished(
});
}
-export async function runTaskWithErrorReporting<T1, T2>(
+export async function runTaskWithErrorReporting(
ws: InternalWalletState,
opId: TaskId,
- f: () => Promise<OperationAttemptResult<T1, T2>>,
-): Promise<OperationAttemptResult<T1, T2>> {
+ f: () => Promise<TaskRunResult>,
+): Promise<TaskRunResult> {
let maybeError: TalerErrorDetail | undefined;
try {
const resp = await f();
switch (resp.type) {
- case OperationAttemptResultType.Error:
+ case TaskRunResultType.Error:
await storePendingTaskError(ws, opId, resp.errorDetail);
return resp;
- case OperationAttemptResultType.Finished:
+ case TaskRunResultType.Finished:
await storePendingTaskFinished(ws, opId);
return resp;
- case OperationAttemptResultType.Pending:
+ case TaskRunResultType.Pending:
await storePendingTaskPending(ws, opId);
return resp;
- case OperationAttemptResultType.Longpoll:
+ case TaskRunResultType.Longpoll:
return resp;
}
} catch (e) {
@@ -459,7 +459,7 @@ export async function runTaskWithErrorReporting<T1, T2>(
if (ws.stopped) {
logger.warn("crypto API stopped during shutdown, ignoring error");
return {
- type: OperationAttemptResultType.Error,
+ type: TaskRunResultType.Error,
errorDetail: makeErrorDetail(
TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
{},
@@ -474,7 +474,7 @@ export async function runTaskWithErrorReporting<T1, T2>(
maybeError = e.errorDetail;
await storePendingTaskError(ws, opId, maybeError!);
return {
- type: OperationAttemptResultType.Error,
+ type: TaskRunResultType.Error,
errorDetail: e.errorDetail,
};
} else if (e instanceof Error) {
@@ -492,7 +492,7 @@ export async function runTaskWithErrorReporting<T1, T2>(
);
await storePendingTaskError(ws, opId, maybeError);
return {
- type: OperationAttemptResultType.Error,
+ type: TaskRunResultType.Error,
errorDetail: maybeError,
};
} else {
@@ -504,7 +504,7 @@ export async function runTaskWithErrorReporting<T1, T2>(
);
await storePendingTaskError(ws, opId, maybeError);
return {
- type: OperationAttemptResultType.Error,
+ type: TaskRunResultType.Error,
errorDetail: maybeError,
};
}
@@ -654,59 +654,55 @@ export interface TransactionManager {
abort(): Promise<void>;
suspend(): Promise<void>;
resume(): Promise<void>;
- process(): Promise<OperationAttemptResult>;
+ process(): Promise<TaskRunResult>;
}
-export enum OperationAttemptResultType {
+export enum TaskRunResultType {
Finished = "finished",
Pending = "pending",
Error = "error",
Longpoll = "longpoll",
}
-export type OperationAttemptResult<TSuccess = unknown, TPending = unknown> =
- | OperationAttemptFinishedResult<TSuccess>
- | OperationAttemptErrorResult
- | OperationAttemptLongpollResult
- | OperationAttemptPendingResult<TPending>;
+export type TaskRunResult =
+ | TaskRunFinishedResult
+ | TaskRunErrorResult
+ | TaskRunLongpollResult
+ | TaskRunPendingResult;
-export namespace OperationAttemptResult {
- export function finishedEmpty(): OperationAttemptResult<unknown, unknown> {
+export namespace TaskRunResult {
+ export function finished(): TaskRunResult {
return {
- type: OperationAttemptResultType.Finished,
- result: undefined,
+ type: TaskRunResultType.Finished,
};
}
- export function pendingEmpty(): OperationAttemptResult<unknown, unknown> {
+ export function pending(): TaskRunResult {
return {
- type: OperationAttemptResultType.Pending,
- result: undefined,
+ type: TaskRunResultType.Pending,
};
}
- export function longpoll(): OperationAttemptResult<unknown, unknown> {
+ export function longpoll(): TaskRunResult {
return {
- type: OperationAttemptResultType.Longpoll,
+ type: TaskRunResultType.Longpoll,
};
}
}
-export interface OperationAttemptFinishedResult<T> {
- type: OperationAttemptResultType.Finished;
- result: T;
+export interface TaskRunFinishedResult {
+ type: TaskRunResultType.Finished;
}
-export interface OperationAttemptPendingResult<T> {
- type: OperationAttemptResultType.Pending;
- result: T;
+export interface TaskRunPendingResult {
+ type: TaskRunResultType.Pending;
}
-export interface OperationAttemptErrorResult {
- type: OperationAttemptResultType.Error;
+export interface TaskRunErrorResult {
+ type: TaskRunResultType.Error;
errorDetail: TalerErrorDetail;
}
-export interface OperationAttemptLongpollResult {
- type: OperationAttemptResultType.Longpoll;
+export interface TaskRunLongpollResult {
+ type: TaskRunResultType.Longpoll;
}
export interface RetryInfo {
@@ -942,19 +938,3 @@ export namespace TaskIdentifiers {
return `${PendingTaskType.PeerPushCredit}:${ppi.peerPushPaymentIncomingId}` as TaskId;
}
}
-
-/**
- * Run an operation handler, expect a success result and extract the success value.
- */
-export async function unwrapOperationHandlerResultOrThrow<T>(
- res: OperationAttemptResult<T>,
-): Promise<T> {
- switch (res.type) {
- case OperationAttemptResultType.Finished:
- return res.result;
- case OperationAttemptResultType.Error:
- throw TalerError.fromUncheckedDetail(res.errorDetail);
- default:
- throw Error(`unexpected operation result (${res.type})`);
- }
-}