aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/hooks/config.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/hooks/config.ts')
-rw-r--r--packages/demobank-ui/src/hooks/config.ts40
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;
}