diff options
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; } +// |