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.tsx65
1 files changed, 17 insertions, 48 deletions
diff --git a/packages/demobank-ui/src/pages/RegistrationPage.tsx b/packages/demobank-ui/src/pages/RegistrationPage.tsx
index c6bc3c327..f22475e10 100644
--- a/packages/demobank-ui/src/pages/RegistrationPage.tsx
+++ b/packages/demobank-ui/src/pages/RegistrationPage.tsx
@@ -15,7 +15,6 @@
*/
import { HttpStatusCode, Logger } from "@gnu-taler/taler-util";
import {
- ErrorType,
RequestError,
useTranslationContext,
} from "@gnu-taler/web-util/lib/index.browser";
@@ -25,7 +24,7 @@ import { useBackendContext } from "../context/backend.js";
import { PageStateType } from "../context/pageState.js";
import { useTestingAPI } from "../hooks/access.js";
import { bankUiSettings } from "../settings.js";
-import { undefinedIfEmpty } from "../utils.js";
+import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js";
import { ShowInputErrorLabel } from "./ShowInputErrorLabel.js";
const logger = new Logger("RegistrationPage");
@@ -177,52 +176,22 @@ function RegistrationForm({
onComplete();
} catch (error) {
if (error instanceof RequestError) {
- 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);
- }
- }
+ onError(
+ buildRequestErrorMessage(i18n, error.cause, {
+ onClientError: (status) =>
+ status === HttpStatusCode.Conflict
+ ? i18n.str`That username is already taken`
+ : undefined,
+ }),
+ );
+ } else {
+ onError({
+ title: i18n.str`Operation failed, please report`,
+ description:
+ error instanceof Error
+ ? error.message
+ : JSON.stringify(error),
+ });
}
}
}}