diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-16 10:48:46 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-16 10:49:44 -0300 |
commit | 99f3a3b33c0284d35f2fe8be704b092048db90cc (patch) | |
tree | 8bdb5ba09d22307a9706fb89573a76e9cb9fede5 /packages/taler-wallet-webextension/src/context/alert.ts | |
parent | fc77825639c5da6d4c9a209ad8cf6df77c96fbae (diff) | |
download | wallet-core-99f3a3b33c0284d35f2fe8be704b092048db90cc.tar.xz |
fix nicer error (from email: "wallet ui error")
Diffstat (limited to 'packages/taler-wallet-webextension/src/context/alert.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/context/alert.ts | 71 |
1 files changed, 56 insertions, 15 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; } +// |