summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-04-16 10:48:46 -0300
committerSebastian <sebasjm@gmail.com>2024-04-16 10:49:44 -0300
commit99f3a3b33c0284d35f2fe8be704b092048db90cc (patch)
tree8bdb5ba09d22307a9706fb89573a76e9cb9fede5
parentfc77825639c5da6d4c9a209ad8cf6df77c96fbae (diff)
downloadwallet-core-99f3a3b33c0284d35f2fe8be704b092048db90cc.tar.gz
wallet-core-99f3a3b33c0284d35f2fe8be704b092048db90cc.tar.bz2
wallet-core-99f3a3b33c0284d35f2fe8be704b092048db90cc.zip
fix nicer error (from email: "wallet ui error")
-rw-r--r--packages/taler-wallet-webextension/src/context/alert.ts71
-rw-r--r--packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts4
2 files changed, 58 insertions, 17 deletions
diff --git a/packages/taler-wallet-webextension/src/context/alert.ts b/packages/taler-wallet-webextension/src/context/alert.ts
index 36de7c7e4..e30fdd72c 100644
--- a/packages/taler-wallet-webextension/src/context/alert.ts
+++ b/packages/taler-wallet-webextension/src/context/alert.ts
@@ -19,13 +19,21 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
-import { TalerError, TalerErrorCode, TalerErrorDetail, TranslatedString } from "@gnu-taler/taler-util";
+import {
+ TalerError,
+ TalerErrorCode,
+ TalerErrorDetail,
+ TranslatedString,
+} from "@gnu-taler/taler-util";
import { ComponentChildren, createContext, h, VNode } from "preact";
import { useContext, useState } from "preact/hooks";
import { HookError } from "../hooks/useAsyncAsHook.js";
import { SafeHandler, withSafe } from "../mui/handlers.js";
import { BackgroundError } from "../wxApi.js";
-import { InternationalizationAPI, useTranslationContext } from "@gnu-taler/web-util/browser";
+import {
+ InternationalizationAPI,
+ useTranslationContext,
+} from "@gnu-taler/web-util/browser";
import { platform } from "../platform/foreground.js";
export type AlertType = "info" | "warning" | "error" | "success";
@@ -175,9 +183,14 @@ export function alertFromError(
//HookError
description = error.message as TranslatedString;
if (error.type === "taler") {
- const msg = isWalletNotAvailable(i18n,error.details)
+ const msg = isWalletNotAvailable(i18n, error.details);
if (msg) {
- description = msg
+ description = msg;
+ } else {
+ const msg2 = isHttpError(i18n, error.details);
+ if (msg2) {
+ description = msg2;
+ }
}
cause = {
details: error.details,
@@ -185,12 +198,17 @@ export function alertFromError(
}
} else {
if (error instanceof BackgroundError) {
- const msg = isWalletNotAvailable(i18n,error.errorDetail)
+ const msg = isWalletNotAvailable(i18n, error.errorDetail);
if (msg) {
- description = msg
+ description = msg;
} else {
- description = (error.errorDetail.hint ??
- `Error code: ${error.errorDetail.code}`) as TranslatedString;
+ const msg2 = isHttpError(i18n, error.errorDetail);
+ if (msg2) {
+ description = msg2;
+ } else {
+ description = (error.errorDetail.hint ??
+ `Error code: ${error.errorDetail.code}`) as TranslatedString;
+ }
}
cause = {
details: error.errorDetail,
@@ -217,20 +235,43 @@ export function alertFromError(
};
}
-function isWalletNotAvailable(i18n: InternationalizationAPI, detail: TalerErrorDetail): TranslatedString | undefined {
- if (detail.code === TalerErrorCode.WALLET_CORE_NOT_AVAILABLE
- && detail.lastError) {
- const le = detail.lastError as TalerErrorDetail
+function isWalletNotAvailable(
+ i18n: InternationalizationAPI,
+ detail: TalerErrorDetail,
+): TranslatedString | undefined {
+ if (
+ detail.code === TalerErrorCode.WALLET_CORE_NOT_AVAILABLE &&
+ detail.lastError
+ ) {
+ const le = detail.lastError as TalerErrorDetail;
if (le.code === TalerErrorCode.WALLET_DB_UNAVAILABLE) {
if (platform.isFirefox() && platform.runningOnPrivateMode()) {
- return i18n.str`Could not open the wallet database. Firefox is known to run into this problem under "permanent private mode".`
+ return i18n.str`Could not open the wallet database. Firefox is known to run into this problem under "permanent private mode".`;
} else {
- return i18n.str`Could not open the wallet database.`
+ return i18n.str`Could not open the wallet database.`;
}
} else {
return (detail.hint ?? `Error code: ${detail.code}`) as TranslatedString;
}
+ }
+ return undefined;
+}
+function isHttpError(
+ i18n: InternationalizationAPI,
+ detail: TalerErrorDetail,
+): TranslatedString | undefined {
+ if (
+ detail.code === TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR &&
+ detail.errorResponse
+ ) {
+ const er = detail.errorResponse as TalerErrorDetail;
+ return (
+ (er.hint as TranslatedString) ??
+ detail.hint ??
+ i18n.str`Unexpected request error, code: ${er.code}`
+ );
}
- return undefined
+ return undefined;
}
+//
diff --git a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts
index b9257215f..75910549f 100644
--- a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts
+++ b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts
@@ -14,7 +14,7 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-import { Amounts } from "@gnu-taler/taler-util";
+import { Amounts, PreparePayResult } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { useState } from "preact/hooks";
import { alertFromError, useAlertContext } from "../../context/alert.js";
@@ -54,7 +54,7 @@ export function useComponentState({
const hook = useAsyncAsHook(async () => {
if (!talerTemplateUri) throw Error("ERROR_NO-URI-FOR-PAYMENT-TEMPLATE");
- let payStatus;
+ let payStatus: PreparePayResult | undefined = undefined;
if (!amountParam && !summaryParam) {
payStatus = await api.wallet.call(
WalletApiOperation.PreparePayForTemplate,