From cfe7129c4ecaa3057d5e47040f0a9efd8ed0317e Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Fri, 7 Apr 2023 18:46:25 -0300
Subject: adding unreadable http response case and removing deprecated fields

---
 .../merchant-backoffice-ui/src/Application.tsx     | 67 ++++++++++++++--------
 1 file changed, 43 insertions(+), 24 deletions(-)

(limited to 'packages/merchant-backoffice-ui/src/Application.tsx')

diff --git a/packages/merchant-backoffice-ui/src/Application.tsx b/packages/merchant-backoffice-ui/src/Application.tsx
index ed1fc69f3..354212946 100644
--- a/packages/merchant-backoffice-ui/src/Application.tsx
+++ b/packages/merchant-backoffice-ui/src/Application.tsx
@@ -20,6 +20,7 @@
  */
 
 import {
+  ErrorType,
   TranslationProvider,
   useTranslationContext,
 } from "@gnu-taler/web-util/lib/index.browser";
@@ -40,6 +41,7 @@ import { ConfigContextProvider } from "./context/config.js";
 import { useBackendConfig } from "./hooks/backend.js";
 import { strings } from "./i18n/strings.js";
 import LoginPage from "./paths/login/index.js";
+import { HttpStatusCode } from "@gnu-taler/taler-util";
 
 export function Application(): VNode {
   return (
@@ -77,47 +79,63 @@ function ApplicationStatusRoutes(): VNode {
     );
   }
 
-  if (result.clientError && result.isUnauthorized)
-    return (
-      <Fragment>
-        <NotYetReadyAppMenu title="Login" />
-        <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
-      </Fragment>
-    );
-
-  if (result.clientError && result.isNotfound)
-    return (
+  if (!result.ok) {
+    if (result.loading) return <Loading />;
+    if (
+      result.type === ErrorType.CLIENT &&
+      result.status === HttpStatusCode.Unauthorized
+    ) {
+      return (
+        <Fragment>
+          <NotYetReadyAppMenu title="Login" />
+          <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+        </Fragment>
+      );
+    }
+    if (
+      result.type === ErrorType.CLIENT &&
+      result.status === HttpStatusCode.NotFound
+    ) {
+      return (
+        <Fragment>
+          <NotYetReadyAppMenu title="Error" />
+          <NotificationCard
+            notification={{
+              message: i18n.str`Server not found`,
+              type: "ERROR",
+              description: `Check your url`,
+            }}
+          />
+          <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+        </Fragment>
+      );
+    }
+    if (result.type === ErrorType.SERVER) {
       <Fragment>
         <NotYetReadyAppMenu title="Error" />
         <NotificationCard
           notification={{
-            message: i18n.str`Server not found`,
+            message: i18n.str`Server response with an error code`,
             type: "ERROR",
-            description: `Check your url`,
+            description: i18n.str`Got message ${result.message} from ${result.info?.url}`,
           }}
         />
         <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
-      </Fragment>
-    );
-
-  if (result.serverError)
-    return (
+      </Fragment>;
+    }
+    if (result.type === ErrorType.UNREADABLE) {
       <Fragment>
         <NotYetReadyAppMenu title="Error" />
         <NotificationCard
           notification={{
-            message: i18n.str`Couldn't access the server`,
+            message: i18n.str`Response from server is unreadable, http status: ${result.status}`,
             type: "ERROR",
             description: i18n.str`Got message ${result.message} from ${result.info?.url}`,
           }}
         />
         <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
-      </Fragment>
-    );
-
-  if (result.loading) return <Loading />;
-
-  if (!result.ok)
+      </Fragment>;
+    }
     return (
       <Fragment>
         <NotYetReadyAppMenu title="Error" />
@@ -131,6 +149,7 @@ function ApplicationStatusRoutes(): VNode {
         <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
       </Fragment>
     );
+  }
 
   return (
     <div class="has-navbar-fixed-top">
-- 
cgit v1.2.3

