commit 38209eedf6d58457ab55b44fa38844641b20c263
parent e22aa38398f2c1d84ca9960757543ad65c34721c
Author: Florian Dold <florian@dold.me>
Date: Mon, 1 Jun 2026 16:09:46 +0200
wallet-core: slightly improve peer push credit error handling
Diffstat:
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/packages/taler-util/src/operation.ts b/packages/taler-util/src/operation.ts
@@ -286,6 +286,19 @@ export function succeedOrThrow<R>(result: OperationResult<R, unknown>): R {
throw TalerError.fromException(result);
}
+export function throwUnexpectedResponse(
+ result: OperationResult<unknown, unknown>,
+): never {
+ const resp = result.response;
+ throw TalerError.fromUncheckedDetail({
+ case: result.case,
+ requestUrl: resp.requestUrl,
+ requestMethod: resp.requestMethod,
+ httpStatusCode: resp.status,
+ errorResponse: "detail" in result ? result.detail : undefined,
+ } as any);
+}
+
/**
* The operation is expected to fail.
* Return the error details.
diff --git a/packages/taler-wallet-core/src/pay-peer-push-debit.ts b/packages/taler-wallet-core/src/pay-peer-push-debit.ts
@@ -54,6 +54,7 @@ import {
getRandomBytes,
j2s,
stringifyPayPushUri,
+ throwUnexpectedResponse,
} from "@gnu-taler/taler-util";
import {
PreviousPayCoins,
@@ -856,13 +857,24 @@ async function processPeerPushDebitAbortingDeletePurse(
switch (resp.case) {
case "ok":
+ // Successfully deleted the purse, we now refresh.
+ break;
case HttpStatusCode.NotFound:
+ // Not found => Previous deletion succeeded.
+ // FIXME: Look at response error code more closely
break;
case HttpStatusCode.Conflict:
- throw Error("purse deletion conflict");
+ // FIXME: Unclear what we do here.
+ // Either the purse got merged or expired.
+ // If it expired, we must refresh.
+ // If not, unclear how we got here
+ // in the first place.
+ break;
case HttpStatusCode.Forbidden:
await ctx.failTransaction(peerPushInitiation.status, resp.detail);
return TaskRunResult.finished();
+ default:
+ throwUnexpectedResponse(resp);
}
await wex.runLegacyWalletDbTx(async (tx) => {