diff options
author | Sebastian <sebasjm@gmail.com> | 2023-09-25 14:49:47 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-09-25 14:50:46 -0300 |
commit | ea0738ccd585445d7e2080d9009025dde9cf22c5 (patch) | |
tree | 1e89ceadefb2b66d8c762358c794f070c2f10dcd /packages/demobank-ui/src/hooks/config.ts | |
parent | 820f953b96b2b2852c32dc16a2fa920c6c717788 (diff) | |
download | wallet-core-ea0738ccd585445d7e2080d9009025dde9cf22c5.tar.xz |
better /config error
Diffstat (limited to 'packages/demobank-ui/src/hooks/config.ts')
-rw-r--r-- | packages/demobank-ui/src/hooks/config.ts | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/packages/demobank-ui/src/hooks/config.ts b/packages/demobank-ui/src/hooks/config.ts index 4b22e8ad3..4cf677d35 100644 --- a/packages/demobank-ui/src/hooks/config.ts +++ b/packages/demobank-ui/src/hooks/config.ts @@ -1,5 +1,5 @@ import { LibtoolVersion } from "@gnu-taler/taler-util"; -import { useApiContext } from "@gnu-taler/web-util/browser"; +import { ErrorType, HttpError, HttpResponseServerError, RequestError, useApiContext } from "@gnu-taler/web-util/browser"; import { useEffect, useState } from "preact/hooks"; import { getInitialBackendBaseURL } from "./backend.js"; @@ -12,38 +12,32 @@ export const BANK_INTEGRATION_PROTOCOL_VERSION = "0:0:0"; async function getConfigState( request: ReturnType<typeof useApiContext>["request"], -): Promise<SandboxBackend.Config | undefined> { - try { - const url = getInitialBackendBaseURL(); - const result = await request<SandboxBackend.Config>( - url, - `config`, - ); - return result.data; - } catch (error) { - return undefined; - } +): Promise<SandboxBackend.Config> { + const url = getInitialBackendBaseURL(); + const result = await request<SandboxBackend.Config>(url, `config`); + return result.data; } -export function useConfigState(): boolean | undefined { - const [checked, setChecked] = useState<boolean>() +export function useConfigState(): undefined | true | string | HttpError<SandboxBackend.SandboxError> { + const [checked, setChecked] = useState<true | string | HttpError<SandboxBackend.SandboxError>>() const { request } = useApiContext(); useEffect(() => { - getConfigState(request) - .then((result) => { - if (!result) { - setChecked(false) + .then((s) => { + const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, s.version) + if (r?.compatible) { + setChecked(true); } else { - const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, result.version) - setChecked(r?.compatible); + setChecked(s.version) } }) - .catch((error) => { - setChecked(false); + .catch((error: unknown) => { + if (error instanceof RequestError) { + setChecked(error.cause); + } }); - }); + }, []); return checked; } |