add 'when' to error-detail and remove error as normal response when doing backup

This commit is contained in:
Sebastian 2023-01-09 20:09:54 -03:00
parent efb5bf9de4
commit 8a70edb2f8
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
6 changed files with 17 additions and 20 deletions

View File

@ -249,6 +249,7 @@ export interface ConfirmPayResultPending {
export const codecForTalerErrorDetail = (): Codec<TalerErrorDetail> =>
buildCodecForObject<TalerErrorDetail>()
.property("code", codecForNumber())
.property("when", codecForString())
.property("hint", codecOptional(codecForString()))
.build("TalerErrorDetail");
@ -537,6 +538,7 @@ export interface WalletDiagnostics {
export interface TalerErrorDetail {
code: TalerErrorCode;
when: string;
hint?: string;
[x: string]: unknown;
}

View File

@ -74,6 +74,7 @@ export class MyCryptoWorker implements CryptoWorker {
type: "error",
error: {
code: 42,
when: "now",
hint: "bla",
},
};

View File

@ -103,7 +103,8 @@ export function makeErrorDetail<C extends TalerErrorCode>(
if (!hint && !(detail as any).hint) {
hint = getDefaultHint(code);
}
return { code, hint, ...detail };
const when = new Date().toISOString();
return { code, when, hint, ...detail };
}
export function makePendingOperationFailedError(
@ -160,7 +161,8 @@ export class TalerError<T = any> extends Error {
if (!hint) {
hint = getDefaultHint(code);
}
return new TalerError<unknown>({ code, hint, ...detail });
const when = new Date().toISOString();
return new TalerError<unknown>({ code, when, hint, ...detail });
}
static fromUncheckedDetail(d: TalerErrorDetail): TalerError {

View File

@ -627,8 +627,7 @@ export const codecForAddBackupProviderRequest =
export type AddBackupProviderResponse =
| AddBackupProviderOk
| AddBackupProviderPaymentRequired
| AddBackupProviderError;
| AddBackupProviderPaymentRequired;
interface AddBackupProviderOk {
status: "ok";
@ -637,10 +636,6 @@ interface AddBackupProviderPaymentRequired {
status: "payment-required";
talerUri?: string;
}
interface AddBackupProviderError {
status: "error";
error: TalerErrorDetail;
}
export const codecForAddBackupProviderOk = (): Codec<AddBackupProviderOk> =>
buildCodecForObject<AddBackupProviderOk>()
@ -654,13 +649,6 @@ export const codecForAddBackupProviderPaymenrRequired =
.property("talerUri", codecOptional(codecForString()))
.build("AddBackupProviderPaymentRequired");
export const codecForAddBackupProviderError =
(): Codec<AddBackupProviderError> =>
buildCodecForObject<AddBackupProviderError>()
.property("status", codecForConstString("error"))
.property("error", codecForTalerErrorDetail())
.build("AddBackupProviderError");
export const codecForAddBackupProviderResponse =
(): Codec<AddBackupProviderResponse> =>
buildCodecForUnion<AddBackupProviderResponse>()
@ -670,7 +658,6 @@ export const codecForAddBackupProviderResponse =
"payment-required",
codecForAddBackupProviderPaymenrRequired(),
)
.alternative("error", codecForAddBackupProviderError())
.build("AddBackupProviderResponse");
export async function addBackupProvider(
@ -745,10 +732,10 @@ async function runFirstBackupCycleForProvider(
const resp = await runBackupCycleForProvider(ws, args);
switch (resp.type) {
case OperationAttemptResultType.Error:
return {
status: "error",
error: resp.errorDetail,
};
throw TalerError.fromDetail(
TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
resp.errorDetail,
);
case OperationAttemptResultType.Finished:
return {
status: "ok",

View File

@ -55,6 +55,7 @@ import {
ExchangeHandle,
canonicalizeBaseUrl,
parsePaytoUri,
TalerErrorCode,
} from "@gnu-taler/taler-util";
import {
AllowedAuditorInfo,
@ -66,6 +67,7 @@ import { GetReadOnlyAccess } from "../util/query.js";
import { InternalWalletState } from "../internal-wallet-state.js";
import { getExchangeDetails } from "./exchanges.js";
import { checkLogicInvariant } from "../util/invariants.js";
import { TalerError } from "../errors.js";
/**
* Logger.

View File

@ -1824,6 +1824,7 @@ export async function processPurchase(
errorDetail: {
// FIXME: allocate more specific error code
code: TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
when: new Date().toISOString(),
hint: `trying to pay for purchase that is not in the database`,
proposalId: proposalId,
},
@ -1874,6 +1875,7 @@ export async function processPurchasePay(
errorDetail: {
// FIXME: allocate more specific error code
code: TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
when: new Date().toISOString(),
hint: `trying to pay for purchase that is not in the database`,
proposalId: proposalId,
},
@ -1996,6 +1998,7 @@ export async function processPurchasePay(
await scheduleRetry(ws, RetryTags.forPay(purchase), {
code: TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
when: new Date().toISOString(),
message: "unexpected exception",
hint: "unexpected exception",
details: {