aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/RegistrationPage.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/pages/RegistrationPage.tsx')
-rw-r--r--packages/demobank-ui/src/pages/RegistrationPage.tsx69
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");
+}