From 1723f16b9c4b008e9e44578c2587c7a1bd6560b4 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Sat, 25 Feb 2023 19:43:45 -0300
Subject: some fixes afte testing demobank with ms

---
 packages/demobank-ui/src/pages/HomePage.tsx | 56 ++++++++++++++++++++++++-----
 1 file changed, 47 insertions(+), 9 deletions(-)

(limited to 'packages/demobank-ui/src/pages/HomePage.tsx')

diff --git a/packages/demobank-ui/src/pages/HomePage.tsx b/packages/demobank-ui/src/pages/HomePage.tsx
index 5af195f48..a360bd64c 100644
--- a/packages/demobank-ui/src/pages/HomePage.tsx
+++ b/packages/demobank-ui/src/pages/HomePage.tsx
@@ -14,9 +14,11 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
-import { Logger } from "@gnu-taler/taler-util";
+import { HttpStatusCode, Logger } from "@gnu-taler/taler-util";
 import {
+  ErrorType,
   HttpResponsePaginated,
+  RequestError,
   useTranslationContext,
 } from "@gnu-taler/web-util/lib/index.browser";
 import { Fragment, h, VNode } from "preact";
@@ -119,9 +121,9 @@ function handleNotOkResult(
   onErrorHandler: (state: PageStateType["error"]) => void,
   i18n: ReturnType<typeof useTranslationContext>["i18n"],
   onRegister: () => void,
-): <T, E>(result: HttpResponsePaginated<T, E>) => VNode {
-  return function handleNotOkResult2<T, E>(
-    result: HttpResponsePaginated<T, E>,
+): <T>(result: HttpResponsePaginated<T, SandboxBackend.SandboxError>) => VNode {
+  return function handleNotOkResult2<T>(
+    result: HttpResponsePaginated<T, SandboxBackend.SandboxError>,
   ): VNode {
     if (result.clientError && result.isUnauthorized) {
       onErrorHandler({
@@ -137,13 +139,49 @@ function handleNotOkResult(
     }
     if (result.loading) return <Loading />;
     if (!result.ok) {
-      onErrorHandler({
-        title: i18n.str`The backend reported a problem: HTTP status #${result.status}`,
-        description: `Diagnostic from ${result.info?.url} is "${result.message}"`,
-        debug: JSON.stringify(result.error),
-      });
+      switch (result.type) {
+        case ErrorType.TIMEOUT: {
+          onErrorHandler({
+            title: i18n.str`Request timeout, try again later.`,
+          });
+          break;
+        }
+        case ErrorType.CLIENT: {
+          const errorData = result.error;
+          onErrorHandler({
+            title: i18n.str`Could not load due to a client error`,
+            description: errorData.error.description,
+            debug: JSON.stringify(result),
+          });
+          break;
+        }
+        case ErrorType.SERVER: {
+          const errorData = result.error;
+          onErrorHandler({
+            title: i18n.str`Server returned with error`,
+            description: errorData.error.description,
+            debug: JSON.stringify(result),
+          });
+          break;
+        }
+        case ErrorType.UNEXPECTED: {
+          onErrorHandler({
+            title: i18n.str`Unexpected error.`,
+            description: `Diagnostic from ${result.info?.url} is "${result.message}"`,
+            debug: JSON.stringify(result.error),
+          });
+          break;
+        }
+        default: {
+          assertUnreachable(result);
+        }
+      }
+
       return <LoginForm onRegister={onRegister} />;
     }
     return <div />;
   };
 }
+export function assertUnreachable(x: never): never {
+  throw new Error("Didn't expect to get here");
+}
-- 
cgit v1.2.3

