From 5d23eb36354d07508a015531f298b3e261bbafce Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 22 Mar 2022 21:16:38 +0100 Subject: wallet: improve error handling and error codes --- packages/taler-wallet-webextension/src/cta/Deposit.tsx | 14 +++++++------- packages/taler-wallet-webextension/src/cta/Pay.tsx | 4 ++-- packages/taler-wallet-webextension/src/cta/Withdraw.tsx | 13 ++++++------- 3 files changed, 15 insertions(+), 16 deletions(-) (limited to 'packages/taler-wallet-webextension/src/cta') diff --git a/packages/taler-wallet-webextension/src/cta/Deposit.tsx b/packages/taler-wallet-webextension/src/cta/Deposit.tsx index ac6c1fd6d..933195a9e 100644 --- a/packages/taler-wallet-webextension/src/cta/Deposit.tsx +++ b/packages/taler-wallet-webextension/src/cta/Deposit.tsx @@ -35,7 +35,7 @@ import { PreparePayResultType, Translate, } from "@gnu-taler/taler-util"; -import { OperationFailedError } from "@gnu-taler/taler-wallet-core"; +import { TalerError } from "@gnu-taler/taler-wallet-core"; import { Fragment, h, VNode } from "preact"; import { useEffect, useState } from "preact/hooks"; import { ErrorTalerOperation } from "../components/ErrorTalerOperation"; @@ -64,9 +64,9 @@ export function DepositPage({ talerPayUri, goBack }: Props): VNode { const [payResult, setPayResult] = useState( undefined, ); - const [payErrMsg, setPayErrMsg] = useState< - OperationFailedError | string | undefined - >(undefined); + const [payErrMsg, setPayErrMsg] = useState( + undefined, + ); const balance = useAsyncAsHook(wxApi.getBalance, [ NotificationType.CoinWithdrawn, @@ -97,7 +97,7 @@ export function DepositPage({ talerPayUri, goBack }: Props): VNode { setPayStatus(p); } catch (e) { console.log("Got error while trying to pay", e); - if (e instanceof OperationFailedError) { + if (e instanceof TalerError) { setPayErrMsg(e); } if (e instanceof Error) { @@ -117,7 +117,7 @@ export function DepositPage({ talerPayUri, goBack }: Props): VNode { } if (!payStatus) { - if (payErrMsg instanceof OperationFailedError) { + if (payErrMsg instanceof TalerError) { return ( @@ -131,7 +131,7 @@ export function DepositPage({ talerPayUri, goBack }: Props): VNode { Could not get the payment information for this order } - error={payErrMsg?.operationError} + error={payErrMsg?.errorDetail} /> diff --git a/packages/taler-wallet-webextension/src/cta/Pay.tsx b/packages/taler-wallet-webextension/src/cta/Pay.tsx index 2a0d1b46b..f6ae02f72 100644 --- a/packages/taler-wallet-webextension/src/cta/Pay.tsx +++ b/packages/taler-wallet-webextension/src/cta/Pay.tsx @@ -36,7 +36,7 @@ import { PreparePayResultType, Product, } from "@gnu-taler/taler-util"; -import { OperationFailedError } from "@gnu-taler/taler-wallet-core"; +import { TalerError } from "@gnu-taler/taler-wallet-core"; import { Fragment, h, VNode } from "preact"; import { useEffect, useState } from "preact/hooks"; import { ErrorMessage } from "../components/ErrorMessage"; @@ -93,7 +93,7 @@ export function PayPage({ undefined, ); const [payErrMsg, setPayErrMsg] = useState< - OperationFailedError | string | undefined + TalerError | string | undefined >(undefined); const hook = useAsyncAsHook(async () => { diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx index 66c83cf15..d58e2ec80 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx @@ -25,10 +25,8 @@ import { AmountJson, Amounts, ExchangeListItem, - Translate, WithdrawUriInfoResponse, } from "@gnu-taler/taler-util"; -import { OperationFailedError } from "@gnu-taler/taler-wallet-core"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { Loading } from "../components/Loading"; @@ -52,6 +50,7 @@ import { import * as wxApi from "../wxApi"; import { TermsOfServiceSection } from "./TermsOfServiceSection"; import { useTranslationContext } from "../context/translation"; +import { TalerError } from "@gnu-taler/taler-wallet-core"; interface Props { talerWithdrawUri?: string; @@ -85,9 +84,9 @@ export function View({ reviewed, }: ViewProps): VNode { const { i18n } = useTranslationContext(); - const [withdrawError, setWithdrawError] = useState< - OperationFailedError | undefined - >(undefined); + const [withdrawError, setWithdrawError] = useState( + undefined, + ); const [confirmDisabled, setConfirmDisabled] = useState(false); const needsReview = terms.status === "changed" || terms.status === "new"; @@ -109,7 +108,7 @@ export function View({ setConfirmDisabled(true); await onWithdraw(); } catch (e) { - if (e instanceof OperationFailedError) { + if (e instanceof TalerError) { setWithdrawError(e); } setConfirmDisabled(false); @@ -130,7 +129,7 @@ export function View({ Could not finish the withdrawal operation } - error={withdrawError.operationError} + error={withdrawError.errorDetail} /> )} -- cgit v1.2.3