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

---
 .../src/ApplicationReadyRoutes.tsx                 | 40 +++++++++++++---------
 1 file changed, 23 insertions(+), 17 deletions(-)

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

diff --git a/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx b/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx
index aeb032fd4..1d4c08cd1 100644
--- a/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx
+++ b/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx
@@ -18,7 +18,10 @@
  *
  * @author Sebastian Javier Marchano (sebasjm)
  */
-import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser";
+import {
+  ErrorType,
+  useTranslationContext,
+} from "@gnu-taler/web-util/lib/index.browser";
 import { createHashHistory } from "history";
 import { Fragment, h, VNode } from "preact";
 import { Router, Route, route } from "preact-router";
@@ -32,6 +35,7 @@ import { useBackendInstancesTestForAdmin } from "./hooks/backend.js";
 import { InstanceRoutes } from "./InstanceRoutes.js";
 import LoginPage from "./paths/login/index.js";
 import { INSTANCE_ID_LOOKUP } from "./utils/constants.js";
+import { HttpStatusCode } from "@gnu-taler/taler-util";
 
 export function ApplicationReadyRoutes(): VNode {
   const { i18n } = useTranslationContext();
@@ -48,28 +52,30 @@ export function ApplicationReadyRoutes(): VNode {
     route("/");
   };
 
-  if (result.clientError && result.isUnauthorized) {
-    return (
-      <Fragment>
-        <NotYetReadyAppMenu title="Login" onLogout={clearTokenAndGoToRoot} />
-        <NotificationCard
-          notification={{
-            message: i18n.str`Access denied`,
-            description: i18n.str`Check your token is valid`,
-            type: "ERROR",
-          }}
-        />
-        <LoginPage onConfirm={updateLoginStatus} />
-      </Fragment>
-    );
-  }
-
   if (result.loading) return <NotYetReadyAppMenu title="Loading..." />;
 
   let admin = true;
   let instanceNameByBackendURL;
 
   if (!result.ok) {
+    if (
+      result.type === ErrorType.CLIENT &&
+      result.status === HttpStatusCode.Unauthorized
+    ) {
+      return (
+        <Fragment>
+          <NotYetReadyAppMenu title="Login" onLogout={clearTokenAndGoToRoot} />
+          <NotificationCard
+            notification={{
+              message: i18n.str`Access denied`,
+              description: i18n.str`Check your token is valid`,
+              type: "ERROR",
+            }}
+          />
+          <LoginPage onConfirm={updateLoginStatus} />
+        </Fragment>
+      );
+    }
     const path = new URL(backendURL).pathname;
     const match = INSTANCE_ID_LOOKUP.exec(path);
     if (!match || !match[1]) {
-- 
cgit v1.2.3

