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/Routing.tsx | 56 +++++++++++++++++++++++++-----
 1 file changed, 47 insertions(+), 9 deletions(-)

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

diff --git a/packages/demobank-ui/src/pages/Routing.tsx b/packages/demobank-ui/src/pages/Routing.tsx
index 48f226574..8234d8988 100644
--- a/packages/demobank-ui/src/pages/Routing.tsx
+++ b/packages/demobank-ui/src/pages/Routing.tsx
@@ -15,6 +15,7 @@
  */
 
 import {
+  ErrorType,
   HttpResponsePaginated,
   useTranslationContext,
 } from "@gnu-taler/web-util/lib/index.browser";
@@ -34,9 +35,9 @@ function handleNotOkResult(
   safe: string,
   saveError: (state: PageStateType["error"]) => void,
   i18n: ReturnType<typeof useTranslationContext>["i18n"],
-): <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) {
       route(safe);
@@ -50,12 +51,45 @@ function handleNotOkResult(
     }
     if (result.loading) return <Loading />;
     if (!result.ok) {
-      saveError({
-        title: i18n.str`The backend reported a problem: HTTP status #${result.status}`,
-        description: i18n.str`Diagnostic from ${result.info?.url} is "${result.message}"`,
-        debug: JSON.stringify(result.error),
-      });
-      route(safe);
+      switch (result.type) {
+        case ErrorType.TIMEOUT: {
+          saveError({
+            title: i18n.str`Request timeout, try again later.`,
+          });
+          break;
+        }
+        case ErrorType.CLIENT: {
+          const errorData = result.error;
+          saveError({
+            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;
+          saveError({
+            title: i18n.str`Server returned with error`,
+            description: errorData.error.description,
+            debug: JSON.stringify(result),
+          });
+          break;
+        }
+        case ErrorType.UNEXPECTED: {
+          saveError({
+            title: i18n.str`Unexpected error.`,
+            description: `Diagnostic from ${result.info?.url} is "${result.message}"`,
+            debug: JSON.stringify(result.error),
+          });
+          break;
+        }
+        default:
+          {
+            assertUnreachable(result);
+          }
+          route(safe);
+      }
     }
     return <div />;
   };
@@ -137,3 +171,7 @@ function Redirect({ to }: { to: string }): VNode {
   }, []);
   return <div>being redirected to {to}</div>;
 }
+
+export function assertUnreachable(x: never): never {
+  throw new Error("Didn't expect to get here");
+}
-- 
cgit v1.2.3

