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

---
 .../demobank-ui/src/pages/RegistrationPage.tsx     | 69 ++++++++++++++++------
 1 file changed, 50 insertions(+), 19 deletions(-)

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

diff --git a/packages/demobank-ui/src/pages/RegistrationPage.tsx b/packages/demobank-ui/src/pages/RegistrationPage.tsx
index 247ef8d80..c6bc3c327 100644
--- a/packages/demobank-ui/src/pages/RegistrationPage.tsx
+++ b/packages/demobank-ui/src/pages/RegistrationPage.tsx
@@ -15,6 +15,7 @@
  */
 import { HttpStatusCode, Logger } from "@gnu-taler/taler-util";
 import {
+  ErrorType,
   RequestError,
   useTranslationContext,
 } from "@gnu-taler/web-util/lib/index.browser";
@@ -176,26 +177,52 @@ function RegistrationForm({
                     onComplete();
                   } catch (error) {
                     if (error instanceof RequestError) {
-                      const errorData: SandboxBackend.SandboxError =
-                        error.info.error;
-                      if (error.info.status === HttpStatusCode.Conflict) {
-                        onError({
-                          title: i18n.str`That username is already taken`,
-                          description: errorData.error.description,
-                          debug: JSON.stringify(error.info),
-                        });
-                      } else {
-                        onError({
-                          title: i18n.str`New registration gave response error`,
-                          description: errorData.error.description,
-                          debug: JSON.stringify(error.info),
-                        });
+                      const e =
+                        error as RequestError<SandboxBackend.SandboxError>;
+                      switch (e.cause.type) {
+                        case ErrorType.TIMEOUT: {
+                          onError({
+                            title: i18n.str`Request timeout, try again later.`,
+                          });
+                          break;
+                        }
+                        case ErrorType.CLIENT: {
+                          const errorData = e.cause.error;
+                          if (e.cause.status === HttpStatusCode.Conflict) {
+                            onError({
+                              title: i18n.str`That username is already taken`,
+                              description: errorData.error.description,
+                              debug: JSON.stringify(error.cause),
+                            });
+                          } else {
+                            onError({
+                              title: i18n.str`New registration gave response error`,
+                              description: errorData.error.description,
+                              debug: JSON.stringify(error.cause),
+                            });
+                          }
+                          break;
+                        }
+                        case ErrorType.SERVER: {
+                          const errorData = e.cause.error;
+                          onError({
+                            title: i18n.str`New registration gave response error`,
+                            description: errorData?.error?.description,
+                            debug: JSON.stringify(error.cause),
+                          });
+                          break;
+                        }
+                        case ErrorType.UNEXPECTED: {
+                          onError({
+                            title: i18n.str`Unexpected error doing the registration.`,
+                            debug: JSON.stringify(error.cause),
+                          });
+                          break;
+                        }
+                        default: {
+                          assertUnreachable(e.cause);
+                        }
                       }
-                    } else if (error instanceof Error) {
-                      onError({
-                        title: i18n.str`Registration failed, please report`,
-                        description: error.message,
-                      });
                     }
                   }
                 }}
@@ -222,3 +249,7 @@ function RegistrationForm({
     </Fragment>
   );
 }
+
+export function assertUnreachable(x: never): never {
+  throw new Error("Didn't expect to get here");
+}
-- 
cgit v1.2.3

