diff options
author | Sebastian <sebasjm@gmail.com> | 2023-01-09 20:09:54 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-01-09 20:09:54 -0300 |
commit | 8a70edb2f8e235c3462127b0aa4e1b65aa1aee0b (patch) | |
tree | cef85adaff404ecf3ad9ed823c216776bb2871e4 /packages/taler-wallet-core/src | |
parent | efb5bf9de465be29de06c30c9e8cd78374b7c118 (diff) | |
download | wallet-core-8a70edb2f8e235c3462127b0aa4e1b65aa1aee0b.tar.xz |
add 'when' to error-detail and remove error as normal response when doing backup
Diffstat (limited to 'packages/taler-wallet-core/src')
5 files changed, 15 insertions, 20 deletions
diff --git a/packages/taler-wallet-core/src/crypto/workers/crypto-dispatcher.test.ts b/packages/taler-wallet-core/src/crypto/workers/crypto-dispatcher.test.ts index df2e645a7..ca4a79d20 100644 --- a/packages/taler-wallet-core/src/crypto/workers/crypto-dispatcher.test.ts +++ b/packages/taler-wallet-core/src/crypto/workers/crypto-dispatcher.test.ts @@ -74,6 +74,7 @@ export class MyCryptoWorker implements CryptoWorker { type: "error", error: { code: 42, + when: "now", hint: "bla", }, }; diff --git a/packages/taler-wallet-core/src/errors.ts b/packages/taler-wallet-core/src/errors.ts index 37a31a8aa..308e9c7a8 100644 --- a/packages/taler-wallet-core/src/errors.ts +++ b/packages/taler-wallet-core/src/errors.ts @@ -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 { diff --git a/packages/taler-wallet-core/src/operations/backup/index.ts b/packages/taler-wallet-core/src/operations/backup/index.ts index a44e8f55a..27d27da0d 100644 --- a/packages/taler-wallet-core/src/operations/backup/index.ts +++ b/packages/taler-wallet-core/src/operations/backup/index.ts @@ -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", diff --git a/packages/taler-wallet-core/src/operations/balance.ts b/packages/taler-wallet-core/src/operations/balance.ts index 383aa5dc1..2c57f8af8 100644 --- a/packages/taler-wallet-core/src/operations/balance.ts +++ b/packages/taler-wallet-core/src/operations/balance.ts @@ -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. diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index 6026e0860..570a50c47 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -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: { |