From 8c33e05bf08976403719a17b1faf424109a7eaa5 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 1 Sep 2020 18:27:22 +0530 Subject: harmonized error codes --- packages/taler-wallet-core/src/operations/errors.ts | 10 +++++----- packages/taler-wallet-core/src/operations/exchanges.ts | 6 +++--- packages/taler-wallet-core/src/operations/pay.ts | 10 +++++----- packages/taler-wallet-core/src/operations/recoup.ts | 6 +++--- packages/taler-wallet-core/src/operations/refresh.ts | 6 +++--- packages/taler-wallet-core/src/operations/refund.ts | 6 +++--- packages/taler-wallet-core/src/operations/reserves.ts | 8 ++++---- packages/taler-wallet-core/src/operations/tip.ts | 6 +++--- packages/taler-wallet-core/src/operations/withdraw.ts | 8 ++++---- 9 files changed, 33 insertions(+), 33 deletions(-) (limited to 'packages/taler-wallet-core/src/operations') diff --git a/packages/taler-wallet-core/src/operations/errors.ts b/packages/taler-wallet-core/src/operations/errors.ts index 6d9f44e03..de78203e4 100644 --- a/packages/taler-wallet-core/src/operations/errors.ts +++ b/packages/taler-wallet-core/src/operations/errors.ts @@ -23,7 +23,7 @@ /** * Imports. */ -import { OperationErrorDetails } from "../types/walletTypes"; +import { TalerErrorDetails } from "../types/walletTypes"; import { TalerErrorCode } from "../TalerErrorCode"; /** @@ -31,7 +31,7 @@ import { TalerErrorCode } from "../TalerErrorCode"; * but the error has already been reported by writing it to the database. */ export class OperationFailedAndReportedError extends Error { - constructor(public operationError: OperationErrorDetails) { + constructor(public operationError: TalerErrorDetails) { super(operationError.message); // Set the prototype explicitly. @@ -52,7 +52,7 @@ export class OperationFailedError extends Error { return new OperationFailedError(makeErrorDetails(ec, message, details)); } - constructor(public operationError: OperationErrorDetails) { + constructor(public operationError: TalerErrorDetails) { super(operationError.message); // Set the prototype explicitly. @@ -64,7 +64,7 @@ export function makeErrorDetails( ec: TalerErrorCode, message: string, details: Record, -): OperationErrorDetails { +): TalerErrorDetails { return { code: ec, hint: `Error: ${TalerErrorCode[ec]}`, @@ -80,7 +80,7 @@ export function makeErrorDetails( */ export async function guardOperationException( op: () => Promise, - onOpError: (e: OperationErrorDetails) => Promise, + onOpError: (e: TalerErrorDetails) => Promise, ): Promise { try { return await op(); diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index 3b7f62fe9..76ce874de 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -20,7 +20,7 @@ import { codecForExchangeKeysJson, codecForExchangeWireJson, } from "../types/talerTypes"; -import { OperationErrorDetails } from "../types/walletTypes"; +import { TalerErrorDetails } from "../types/walletTypes"; import { ExchangeRecord, ExchangeUpdateStatus, @@ -86,7 +86,7 @@ async function denominationRecordFromKeys( async function setExchangeError( ws: InternalWalletState, baseUrl: string, - err: OperationErrorDetails, + err: TalerErrorDetails, ): Promise { logger.warn(`last error for exchange ${baseUrl}:`, err); const mut = (exchange: ExchangeRecord): ExchangeRecord => { @@ -438,7 +438,7 @@ export async function updateExchangeFromUrl( baseUrl: string, forceNow = false, ): Promise { - const onOpErr = (e: OperationErrorDetails): Promise => + const onOpErr = (e: TalerErrorDetails): Promise => setExchangeError(ws, baseUrl, e); return await guardOperationException( () => updateExchangeFromUrlImpl(ws, baseUrl, forceNow), diff --git a/packages/taler-wallet-core/src/operations/pay.ts b/packages/taler-wallet-core/src/operations/pay.ts index 7b8a1efac..6981b44fc 100644 --- a/packages/taler-wallet-core/src/operations/pay.ts +++ b/packages/taler-wallet-core/src/operations/pay.ts @@ -46,7 +46,7 @@ import { } from "../types/talerTypes"; import { ConfirmPayResult, - OperationErrorDetails, + TalerErrorDetails, PreparePayResult, RefreshReason, PreparePayResultType, @@ -516,7 +516,7 @@ async function recordConfirmPay( async function incrementProposalRetry( ws: InternalWalletState, proposalId: string, - err: OperationErrorDetails | undefined, + err: TalerErrorDetails | undefined, ): Promise { await ws.db.runWithWriteTransaction([Stores.proposals], async (tx) => { const pr = await tx.get(Stores.proposals, proposalId); @@ -539,7 +539,7 @@ async function incrementProposalRetry( async function incrementPurchasePayRetry( ws: InternalWalletState, proposalId: string, - err: OperationErrorDetails | undefined, + err: TalerErrorDetails | undefined, ): Promise { logger.warn("incrementing purchase pay retry with error", err); await ws.db.runWithWriteTransaction([Stores.purchases], async (tx) => { @@ -565,7 +565,7 @@ export async function processDownloadProposal( proposalId: string, forceNow = false, ): Promise { - const onOpErr = (err: OperationErrorDetails): Promise => + const onOpErr = (err: TalerErrorDetails): Promise => incrementProposalRetry(ws, proposalId, err); await guardOperationException( () => processDownloadProposalImpl(ws, proposalId, forceNow), @@ -1205,7 +1205,7 @@ export async function processPurchasePay( proposalId: string, forceNow = false, ): Promise { - const onOpErr = (e: OperationErrorDetails): Promise => + const onOpErr = (e: TalerErrorDetails): Promise => incrementPurchasePayRetry(ws, proposalId, e); await guardOperationException( () => processPurchasePayImpl(ws, proposalId, forceNow), diff --git a/packages/taler-wallet-core/src/operations/recoup.ts b/packages/taler-wallet-core/src/operations/recoup.ts index ba02f72f8..7896fc275 100644 --- a/packages/taler-wallet-core/src/operations/recoup.ts +++ b/packages/taler-wallet-core/src/operations/recoup.ts @@ -44,7 +44,7 @@ import { forceQueryReserve, getReserveRequestTimeout } from "./reserves"; import { Amounts } from "../util/amounts"; import { createRefreshGroup, processRefreshGroup } from "./refresh"; -import { RefreshReason, OperationErrorDetails } from "../types/walletTypes"; +import { RefreshReason, TalerErrorDetails } from "../types/walletTypes"; import { TransactionHandle } from "../util/query"; import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto"; import { getTimestampNow } from "../util/time"; @@ -58,7 +58,7 @@ const logger = new Logger("operations/recoup.ts"); async function incrementRecoupRetry( ws: InternalWalletState, recoupGroupId: string, - err: OperationErrorDetails | undefined, + err: TalerErrorDetails | undefined, ): Promise { await ws.db.runWithWriteTransaction([Stores.recoupGroups], async (tx) => { const r = await tx.get(Stores.recoupGroups, recoupGroupId); @@ -305,7 +305,7 @@ export async function processRecoupGroup( forceNow = false, ): Promise { await ws.memoProcessRecoup.memo(recoupGroupId, async () => { - const onOpErr = (e: OperationErrorDetails): Promise => + const onOpErr = (e: TalerErrorDetails): Promise => incrementRecoupRetry(ws, recoupGroupId, e); return await guardOperationException( async () => await processRecoupGroupImpl(ws, recoupGroupId, forceNow), diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 89cc3af43..d951cfeb8 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -34,7 +34,7 @@ import { Logger } from "../util/logging"; import { getWithdrawDenomList } from "./withdraw"; import { updateExchangeFromUrl } from "./exchanges"; import { - OperationErrorDetails, + TalerErrorDetails, CoinPublicKey, RefreshReason, RefreshGroupId, @@ -441,7 +441,7 @@ async function refreshReveal( async function incrementRefreshRetry( ws: InternalWalletState, refreshGroupId: string, - err: OperationErrorDetails | undefined, + err: TalerErrorDetails | undefined, ): Promise { await ws.db.runWithWriteTransaction([Stores.refreshGroups], async (tx) => { const r = await tx.get(Stores.refreshGroups, refreshGroupId); @@ -470,7 +470,7 @@ export async function processRefreshGroup( forceNow = false, ): Promise { await ws.memoProcessRefresh.memo(refreshGroupId, async () => { - const onOpErr = (e: OperationErrorDetails): Promise => + const onOpErr = (e: TalerErrorDetails): Promise => incrementRefreshRetry(ws, refreshGroupId, e); return await guardOperationException( async () => await processRefreshGroupImpl(ws, refreshGroupId, forceNow), diff --git a/packages/taler-wallet-core/src/operations/refund.ts b/packages/taler-wallet-core/src/operations/refund.ts index 0d6b9ec86..2c7427c03 100644 --- a/packages/taler-wallet-core/src/operations/refund.ts +++ b/packages/taler-wallet-core/src/operations/refund.ts @@ -25,7 +25,7 @@ */ import { InternalWalletState } from "./state"; import { - OperationErrorDetails, + TalerErrorDetails, RefreshReason, CoinPublicKey, } from "../types/walletTypes"; @@ -65,7 +65,7 @@ const logger = new Logger("refund.ts"); async function incrementPurchaseQueryRefundRetry( ws: InternalWalletState, proposalId: string, - err: OperationErrorDetails | undefined, + err: TalerErrorDetails | undefined, ): Promise { await ws.db.runWithWriteTransaction([Stores.purchases], async (tx) => { const pr = await tx.get(Stores.purchases, proposalId); @@ -438,7 +438,7 @@ export async function processPurchaseQueryRefund( proposalId: string, forceNow = false, ): Promise { - const onOpErr = (e: OperationErrorDetails): Promise => + const onOpErr = (e: TalerErrorDetails): Promise => incrementPurchaseQueryRefundRetry(ws, proposalId, e); await guardOperationException( () => processPurchaseQueryRefundImpl(ws, proposalId, forceNow), diff --git a/packages/taler-wallet-core/src/operations/reserves.ts b/packages/taler-wallet-core/src/operations/reserves.ts index fda3c4bcb..439eb34a6 100644 --- a/packages/taler-wallet-core/src/operations/reserves.ts +++ b/packages/taler-wallet-core/src/operations/reserves.ts @@ -17,7 +17,7 @@ import { CreateReserveRequest, CreateReserveResponse, - OperationErrorDetails, + TalerErrorDetails, AcceptWithdrawalResponse, } from "../types/walletTypes"; import { canonicalizeBaseUrl } from "../util/helpers"; @@ -311,7 +311,7 @@ export async function processReserve( forceNow = false, ): Promise { return ws.memoProcessReserve.memo(reservePub, async () => { - const onOpError = (err: OperationErrorDetails): Promise => + const onOpError = (err: TalerErrorDetails): Promise => incrementReserveRetry(ws, reservePub, err); await guardOperationException( () => processReserveImpl(ws, reservePub, forceNow), @@ -375,7 +375,7 @@ async function processReserveBankStatus( ws: InternalWalletState, reservePub: string, ): Promise { - const onOpError = (err: OperationErrorDetails): Promise => + const onOpError = (err: TalerErrorDetails): Promise => incrementReserveRetry(ws, reservePub, err); await guardOperationException( () => processReserveBankStatusImpl(ws, reservePub), @@ -480,7 +480,7 @@ async function processReserveBankStatusImpl( async function incrementReserveRetry( ws: InternalWalletState, reservePub: string, - err: OperationErrorDetails | undefined, + err: TalerErrorDetails | undefined, ): Promise { await ws.db.runWithWriteTransaction([Stores.reserves], async (tx) => { const r = await tx.get(Stores.reserves, reservePub); diff --git a/packages/taler-wallet-core/src/operations/tip.ts b/packages/taler-wallet-core/src/operations/tip.ts index 6dee9c87e..7949648c5 100644 --- a/packages/taler-wallet-core/src/operations/tip.ts +++ b/packages/taler-wallet-core/src/operations/tip.ts @@ -16,7 +16,7 @@ import { InternalWalletState } from "./state"; import { parseTipUri } from "../util/taleruri"; -import { TipStatus, OperationErrorDetails } from "../types/walletTypes"; +import { TipStatus, TalerErrorDetails } from "../types/walletTypes"; import { TipPlanchetDetail, codecForTipPickupGetResponse, @@ -137,7 +137,7 @@ export async function getTipStatus( async function incrementTipRetry( ws: InternalWalletState, refreshSessionId: string, - err: OperationErrorDetails | undefined, + err: TalerErrorDetails | undefined, ): Promise { await ws.db.runWithWriteTransaction([Stores.tips], async (tx) => { const t = await tx.get(Stores.tips, refreshSessionId); @@ -160,7 +160,7 @@ export async function processTip( tipId: string, forceNow = false, ): Promise { - const onOpErr = (e: OperationErrorDetails): Promise => + const onOpErr = (e: TalerErrorDetails): Promise => incrementTipRetry(ws, tipId, e); await guardOperationException( () => processTipImpl(ws, tipId, forceNow), diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 3977ba121..2ab1ea52d 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -32,7 +32,7 @@ import { import { BankWithdrawDetails, ExchangeWithdrawDetails, - OperationErrorDetails, + TalerErrorDetails, ExchangeListItem, } from "../types/walletTypes"; import { @@ -552,7 +552,7 @@ export async function selectWithdrawalDenoms( async function incrementWithdrawalRetry( ws: InternalWalletState, withdrawalGroupId: string, - err: OperationErrorDetails | undefined, + err: TalerErrorDetails | undefined, ): Promise { await ws.db.runWithWriteTransaction([Stores.withdrawalGroups], async (tx) => { const wsr = await tx.get(Stores.withdrawalGroups, withdrawalGroupId); @@ -574,7 +574,7 @@ export async function processWithdrawGroup( withdrawalGroupId: string, forceNow = false, ): Promise { - const onOpErr = (e: OperationErrorDetails): Promise => + const onOpErr = (e: TalerErrorDetails): Promise => incrementWithdrawalRetry(ws, withdrawalGroupId, e); await guardOperationException( () => processWithdrawGroupImpl(ws, withdrawalGroupId, forceNow), @@ -645,7 +645,7 @@ async function processWithdrawGroupImpl( let numFinished = 0; let finishedForFirstTime = false; - let errorsPerCoin: Record = {}; + let errorsPerCoin: Record = {}; await ws.db.runWithWriteTransaction( [Stores.coins, Stores.withdrawalGroups, Stores.reserves, Stores.planchets], -- cgit v1.2.3