harmonized error codes

This commit is contained in:
Florian Dold 2020-09-01 18:27:22 +05:30
parent 5056da6548
commit 8c33e05bf0
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
14 changed files with 71 additions and 71 deletions

View File

@ -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<string, unknown>,
): OperationErrorDetails {
): TalerErrorDetails {
return {
code: ec,
hint: `Error: ${TalerErrorCode[ec]}`,
@ -80,7 +80,7 @@ export function makeErrorDetails(
*/
export async function guardOperationException<T>(
op: () => Promise<T>,
onOpError: (e: OperationErrorDetails) => Promise<void>,
onOpError: (e: TalerErrorDetails) => Promise<void>,
): Promise<T> {
try {
return await op();

View File

@ -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<void> {
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<ExchangeRecord> {
const onOpErr = (e: OperationErrorDetails): Promise<void> =>
const onOpErr = (e: TalerErrorDetails): Promise<void> =>
setExchangeError(ws, baseUrl, e);
return await guardOperationException(
() => updateExchangeFromUrlImpl(ws, baseUrl, forceNow),

View File

@ -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<void> {
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<void> {
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<void> {
const onOpErr = (err: OperationErrorDetails): Promise<void> =>
const onOpErr = (err: TalerErrorDetails): Promise<void> =>
incrementProposalRetry(ws, proposalId, err);
await guardOperationException(
() => processDownloadProposalImpl(ws, proposalId, forceNow),
@ -1205,7 +1205,7 @@ export async function processPurchasePay(
proposalId: string,
forceNow = false,
): Promise<void> {
const onOpErr = (e: OperationErrorDetails): Promise<void> =>
const onOpErr = (e: TalerErrorDetails): Promise<void> =>
incrementPurchasePayRetry(ws, proposalId, e);
await guardOperationException(
() => processPurchasePayImpl(ws, proposalId, forceNow),

View File

@ -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<void> {
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<void> {
await ws.memoProcessRecoup.memo(recoupGroupId, async () => {
const onOpErr = (e: OperationErrorDetails): Promise<void> =>
const onOpErr = (e: TalerErrorDetails): Promise<void> =>
incrementRecoupRetry(ws, recoupGroupId, e);
return await guardOperationException(
async () => await processRecoupGroupImpl(ws, recoupGroupId, forceNow),

View File

@ -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<void> {
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<void> {
await ws.memoProcessRefresh.memo(refreshGroupId, async () => {
const onOpErr = (e: OperationErrorDetails): Promise<void> =>
const onOpErr = (e: TalerErrorDetails): Promise<void> =>
incrementRefreshRetry(ws, refreshGroupId, e);
return await guardOperationException(
async () => await processRefreshGroupImpl(ws, refreshGroupId, forceNow),

View File

@ -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<void> {
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<void> {
const onOpErr = (e: OperationErrorDetails): Promise<void> =>
const onOpErr = (e: TalerErrorDetails): Promise<void> =>
incrementPurchaseQueryRefundRetry(ws, proposalId, e);
await guardOperationException(
() => processPurchaseQueryRefundImpl(ws, proposalId, forceNow),

View File

@ -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<void> {
return ws.memoProcessReserve.memo(reservePub, async () => {
const onOpError = (err: OperationErrorDetails): Promise<void> =>
const onOpError = (err: TalerErrorDetails): Promise<void> =>
incrementReserveRetry(ws, reservePub, err);
await guardOperationException(
() => processReserveImpl(ws, reservePub, forceNow),
@ -375,7 +375,7 @@ async function processReserveBankStatus(
ws: InternalWalletState,
reservePub: string,
): Promise<void> {
const onOpError = (err: OperationErrorDetails): Promise<void> =>
const onOpError = (err: TalerErrorDetails): Promise<void> =>
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<void> {
await ws.db.runWithWriteTransaction([Stores.reserves], async (tx) => {
const r = await tx.get(Stores.reserves, reservePub);

View File

@ -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<void> {
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<void> {
const onOpErr = (e: OperationErrorDetails): Promise<void> =>
const onOpErr = (e: TalerErrorDetails): Promise<void> =>
incrementTipRetry(ws, tipId, e);
await guardOperationException(
() => processTipImpl(ws, tipId, forceNow),

View File

@ -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<void> {
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<void> {
const onOpErr = (e: OperationErrorDetails): Promise<void> =>
const onOpErr = (e: TalerErrorDetails): Promise<void> =>
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<number, OperationErrorDetails> = {};
let errorsPerCoin: Record<number, TalerErrorDetails> = {};
await ws.db.runWithWriteTransaction(
[Stores.coins, Stores.withdrawalGroups, Stores.reserves, Stores.planchets],

View File

@ -35,7 +35,7 @@ import {
} from "./talerTypes";
import { Index, Store } from "../util/query";
import { OperationErrorDetails, RefreshReason } from "./walletTypes";
import { TalerErrorDetails, RefreshReason } from "./walletTypes";
import {
ReserveTransaction,
ReserveCreditTransaction,
@ -335,7 +335,7 @@ export interface ReserveRecord {
* Last error that happened in a reserve operation
* (either talking to the bank or the exchange).
*/
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
}
/**
@ -649,7 +649,7 @@ export interface ExchangeRecord {
*/
updateDiff: ExchangeUpdateDiff | undefined;
lastError?: OperationErrorDetails;
lastError?: TalerErrorDetails;
}
/**
@ -679,7 +679,7 @@ export interface PlanchetRecord {
withdrawalDone: boolean;
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
/**
* Public key of the reserve, this might be a reserve not
@ -910,14 +910,14 @@ export interface ProposalRecord {
*/
retryInfo: RetryInfo;
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
}
/**
* Status of a tip we got from a merchant.
*/
export interface TipRecord {
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
/**
* Has the user accepted the tip? Only after the tip has been accepted coins
@ -1002,9 +1002,9 @@ export interface RefreshGroupRecord {
*/
retryInfo: RetryInfo;
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
lastErrorPerCoin: { [coinIndex: number]: OperationErrorDetails };
lastErrorPerCoin: { [coinIndex: number]: TalerErrorDetails };
refreshGroupId: string;
@ -1032,7 +1032,7 @@ export interface RefreshGroupRecord {
* Ongoing refresh
*/
export interface RefreshSessionRecord {
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
/**
* Public key that's being melted in this session.
@ -1383,7 +1383,7 @@ export interface PurchaseRecord {
payRetryInfo: RetryInfo;
lastPayError: OperationErrorDetails | undefined;
lastPayError: TalerErrorDetails | undefined;
/**
* Retry information for querying the refund status with the merchant.
@ -1393,7 +1393,7 @@ export interface PurchaseRecord {
/**
* Last error (or undefined) for querying the refund status with the merchant.
*/
lastRefundStatusError: OperationErrorDetails | undefined;
lastRefundStatusError: TalerErrorDetails | undefined;
/**
* Continue querying the refund status until this deadline has expired.
@ -1541,7 +1541,7 @@ export interface WithdrawalGroupRecord {
*/
retryInfo: RetryInfo;
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
}
export interface BankWithdrawUriRecord {
@ -1606,7 +1606,7 @@ export interface RecoupGroupRecord {
/**
* Last error that occured, if any.
*/
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
}
export const enum ImportPayloadType {

View File

@ -22,7 +22,7 @@
/**
* Imports.
*/
import { OperationErrorDetails } from "./walletTypes";
import { TalerErrorDetails } from "./walletTypes";
import { WithdrawalSource } from "./dbTypes";
export const enum NotificationType {
@ -154,32 +154,32 @@ export interface RefundFinishedNotification {
export interface ExchangeOperationErrorNotification {
type: NotificationType.ExchangeOperationError;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface RefreshOperationErrorNotification {
type: NotificationType.RefreshOperationError;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface RefundStatusOperationErrorNotification {
type: NotificationType.RefundStatusOperationError;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface RefundApplyOperationErrorNotification {
type: NotificationType.RefundApplyOperationError;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface PayOperationErrorNotification {
type: NotificationType.PayOperationError;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface ProposalOperationErrorNotification {
type: NotificationType.ProposalOperationError;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface TipOperationErrorNotification {
@ -188,17 +188,17 @@ export interface TipOperationErrorNotification {
export interface WithdrawOperationErrorNotification {
type: NotificationType.WithdrawOperationError;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface RecoupOperationErrorNotification {
type: NotificationType.RecoupOperationError;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface ReserveOperationErrorNotification {
type: NotificationType.ReserveOperationError;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface ReserveCreatedNotification {

View File

@ -21,7 +21,7 @@
/**
* Imports.
*/
import { OperationErrorDetails, BalancesResponse } from "./walletTypes";
import { TalerErrorDetails, BalancesResponse } from "./walletTypes";
import { WithdrawalSource, RetryInfo, ReserveRecordStatus } from "./dbTypes";
import { Timestamp, Duration } from "../util/time";
@ -67,7 +67,7 @@ export interface PendingExchangeUpdateOperation {
stage: ExchangeUpdateOperationStage;
reason: string;
exchangeBaseUrl: string;
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
}
/**
@ -122,7 +122,7 @@ export interface PendingReserveOperation {
*/
export interface PendingRefreshOperation {
type: PendingOperationType.Refresh;
lastError?: OperationErrorDetails;
lastError?: TalerErrorDetails;
refreshGroupId: string;
finishedPerCoin: boolean[];
retryInfo: RetryInfo;
@ -137,7 +137,7 @@ export interface PendingProposalDownloadOperation {
proposalTimestamp: Timestamp;
proposalId: string;
orderId: string;
lastError?: OperationErrorDetails;
lastError?: TalerErrorDetails;
retryInfo: RetryInfo;
}
@ -182,7 +182,7 @@ export interface PendingPayOperation {
proposalId: string;
isReplay: boolean;
retryInfo: RetryInfo;
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
}
/**
@ -193,14 +193,14 @@ export interface PendingRefundQueryOperation {
type: PendingOperationType.RefundQuery;
proposalId: string;
retryInfo: RetryInfo;
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
}
export interface PendingRecoupOperation {
type: PendingOperationType.Recoup;
recoupGroupId: string;
retryInfo: RetryInfo;
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
}
/**
@ -209,7 +209,7 @@ export interface PendingRecoupOperation {
export interface PendingWithdrawOperation {
type: PendingOperationType.Withdraw;
source: WithdrawalSource;
lastError: OperationErrorDetails | undefined;
lastError: TalerErrorDetails | undefined;
retryInfo: RetryInfo;
withdrawalGroupId: string;
numCoinsWithdrawn: number;

View File

@ -42,7 +42,7 @@ import {
codecForList,
codecForAny,
} from "../util/codec";
import { OperationErrorDetails } from "./walletTypes";
import { TalerErrorDetails } from "./walletTypes";
export interface TransactionsRequest {
/**
@ -86,7 +86,7 @@ export interface TransactionCommon {
// Amount added or removed from the wallet's balance (including all fees and other costs)
amountEffective: AmountString;
error?: OperationErrorDetails;
error?: TalerErrorDetails;
}
export type Transaction =

View File

@ -214,7 +214,7 @@ export interface ConfirmPayResultDone {
export interface ConfirmPayResultPending {
type: ConfirmPayResultType.Pending;
lastError: OperationErrorDetails;
lastError: TalerErrorDetails;
}
export type ConfirmPayResult = ConfirmPayResultDone | ConfirmPayResultPending;
@ -494,9 +494,9 @@ export interface WalletDiagnostics {
dbOutdated: boolean;
}
export interface OperationErrorDetails {
talerErrorCode: number;
talerErrorHint: string;
export interface TalerErrorDetails {
code: number;
hint: string;
message: string;
details: unknown;
}
@ -816,7 +816,7 @@ export interface CoreApiResponseError {
type: "error";
operation: string;
id: string;
error: OperationErrorDetails;
error: TalerErrorDetails;
}
export interface WithdrawTestBalanceRequest {