gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: fix nicer error (from email:


From: gnunet
Subject: [taler-wallet-core] branch master updated: fix nicer error (from email: "wallet ui error")
Date: Tue, 16 Apr 2024 15:50:00 +0200

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 99f3a3b33 fix nicer error (from email: "wallet ui error")
99f3a3b33 is described below

commit 99f3a3b33c0284d35f2fe8be704b092048db90cc
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Tue Apr 16 10:48:46 2024 -0300

    fix nicer error (from email: "wallet ui error")
---
 .../taler-wallet-webextension/src/context/alert.ts | 71 +++++++++++++++++-----
 .../src/cta/PaymentTemplate/state.ts               |  4 +-
 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,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]