diff options
author | Sebastian <sebasjm@gmail.com> | 2023-02-25 19:43:45 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-02-25 19:43:59 -0300 |
commit | 1723f16b9c4b008e9e44578c2587c7a1bd6560b4 (patch) | |
tree | 4c10315d97edcdf215e3cd329ffb67231adf135e /packages/demobank-ui/src/pages/RegistrationPage.tsx | |
parent | dd2599ff94f4ecc878abc9f6c87603fd180ac3de (diff) | |
download | wallet-core-1723f16b9c4b008e9e44578c2587c7a1bd6560b4.tar.xz |
some fixes afte testing demobank with ms
Diffstat (limited to 'packages/demobank-ui/src/pages/RegistrationPage.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/RegistrationPage.tsx | 69 |
1 files changed, 50 insertions, 19 deletions
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"); +} |