taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 62f72d086d182d6c9fa7ecb41045e8a699e7bcf0
parent 3b2a424d503e2173e69ed524f225e4468203ccb6
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Sat, 24 Oct 2026 11:06:23 +0200

mailbox/taldir: improve error handling from REST API

Diffstat:
Mpackages/taler-util/src/http-client/taldir.ts | 11+++--------
Mpackages/taler-wallet-core/src/mailbox.ts | 34++++++++--------------------------
Mpackages/taler-wallet-core/src/taldir.ts | 18++----------------
Mpackages/taler-wallet-core/src/wallet-api-types.ts | 2++
4 files changed, 15 insertions(+), 50 deletions(-)

diff --git a/packages/taler-util/src/http-client/taldir.ts b/packages/taler-util/src/http-client/taldir.ts @@ -156,15 +156,10 @@ export class TalerDirectoryInstanceHttpClient { case HttpStatusCode.NoContent: { return opFixedSuccess(resp, resp.status); } - case HttpStatusCode.NotFound: { - return opKnownHttpFailure(resp.status, resp); - } - case HttpStatusCode.Forbidden: { - return opKnownHttpFailure(resp.status, resp); - } - case HttpStatusCode.TooManyRequests: { + case HttpStatusCode.NotFound: + case HttpStatusCode.TooManyRequests: + case HttpStatusCode.Forbidden: return opKnownHttpFailure(resp.status, resp); - } default: return opUnknownHttpFailure(resp); } diff --git a/packages/taler-wallet-core/src/mailbox.ts b/packages/taler-wallet-core/src/mailbox.ts @@ -61,6 +61,7 @@ import { MailboxRegisterRequestHttp, MailboxInitializationRequest, GetMailboxRequest, + opKnownHttpFailure, } from "@gnu-taler/taler-util"; import { WalletExecutionContext } from "./wallet.js"; import { @@ -206,21 +207,9 @@ async function internalRegisterMailbox( wex.http, ); - const resp = await runWithProgressRetries(wex, async () => + return succeedOrThrow(await runWithProgressRetries(wex, async () => await mailboxClient.registerMailbox(httpReq), - ); - switch (resp.case) { - case "ok": - return resp.body; - case HttpStatusCode.Forbidden: - throw TalerError.fromDetail( - TalerErrorCode.GENERIC_FORBIDDEN, - {}, - "the mailbox service refused the registration", - ); - case HttpStatusCode.PaymentRequired: - return resp.body; - } + )); } /** @@ -405,20 +394,13 @@ async function internalRefreshMailbox( batchIndex < MAX_MAILBOX_REFRESH_BATCHES; batchIndex++ ) { - const res = await runWithProgressRetries(wex, async () => + const res = succeedOrThrow(await runWithProgressRetries(wex, async () => await mailboxClient.getMessages({ hMailbox: req.mailboxConf.hAddress, }), - ); - if (res.case !== "ok") { - throw TalerError.fromDetail( - TalerErrorCode.WALLET_MAILBOX_UNAVAILABLE, - { mailboxBaseUrl: req.mailboxConf.mailboxBaseUrl }, - "the mailbox service did not return the messages", - ); - } + )); - const messages = res.body.messages; + const messages = res.messages; const now = TalerProtocolTimestamp.now(); if (messages.byteLength % message_size !== 0) { throw TalerError.fromDetail( @@ -462,7 +444,7 @@ async function internalRefreshMailbox( const vMsg = new DataView(messageBuffer); vMsg.setUint32(0, 4 * 4); vMsg.setUint32(4, TalerSignaturePurpose.MAILBOX_MESSAGES_DELETE); - vMsg.setUint32(8, parseInt(res.body.etag)); + vMsg.setUint32(8, parseInt(res.etag)); vMsg.setUint32(12, numMessages); const signature = eddsaSign( new Uint8Array(messageBuffer), @@ -472,7 +454,7 @@ async function internalRefreshMailbox( succeedOrThrow( await mailboxClient.deleteMessages({ mailboxConf: req.mailboxConf, - matchIf: res.body.etag, + matchIf: res.etag, count: numMessages, signature: encodeCrock(signature), }), diff --git a/packages/taler-wallet-core/src/taldir.ts b/packages/taler-wallet-core/src/taldir.ts @@ -157,7 +157,7 @@ async function internalLookupAlias( ); const hAlias = encodeCrock(sha512(hAliasBuffer)); const res = await runWithProgressRetries(wex, async () => - await taldirClient.lookupAlias({ hAlias: hAlias }), + await taldirClient.lookupAlias({ hAlias: hAlias }), ); switch (res.case) { case "ok": @@ -280,23 +280,9 @@ async function internalCompleteAliasRegistration( case "ok": return {}; case HttpStatusCode.NotFound: - throw TalerError.fromDetail( - TalerErrorCode.WALLET_DIRECTORY_UNAVAILABLE, - { directoryBaseUrl: completionRequest.taldirBaseUrl }, - "the directory service does not know this registration, it may have expired", - ); case HttpStatusCode.Forbidden: - throw TalerError.fromDetail( - TalerErrorCode.GENERIC_FORBIDDEN, - {}, - "the directory service rejected the answer to the challenge", - ); case HttpStatusCode.TooManyRequests: - throw TalerError.fromDetail( - TalerErrorCode.WALLET_DIRECTORY_UNAVAILABLE, - { directoryBaseUrl: completionRequest.taldirBaseUrl }, - "too many attempts have been made to answer this registration challenge", - ); + throw res; default: throw TalerError.fromDetail( TalerErrorCode.WALLET_DIRECTORY_UNAVAILABLE, diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -2090,6 +2090,7 @@ export const walletApiExpectedErrors = { [WalletApiOperation.InitializeMailbox]: [ TalerErrorCode.WALLET_MAILBOX_UNAVAILABLE, + TalerErrorCode.WALLET_MAILBOX_REGISTER_INVALID_SIGNATURE, TalerErrorCode.GENERIC_FORBIDDEN, ], [WalletApiOperation.RefreshMailbox]: [ @@ -2097,6 +2098,7 @@ export const walletApiExpectedErrors = { ], [WalletApiOperation.SendTalerUriMailboxMessage]: [ TalerErrorCode.WALLET_MAILBOX_UNAVAILABLE, + TalerErrorCode.WALLET_MAILBOX_MESSAGE_SEND_DENIED, ], [WalletApiOperation.RegisterAlias]: [ TalerErrorCode.WALLET_DIRECTORY_UNAVAILABLE,