From 9f146413e91521ca241adbf00635cac26e63f73c Mon Sep 17 00:00:00 2001 From: Oksamies Date: Wed, 19 Nov 2025 14:37:36 +0200 Subject: [PATCH] Enhance error handling in user settings routes with user-facing error mapping --- .../app/settings/user/Account/Account.tsx | 107 ++++++++++++------ .../app/settings/user/Settings.tsx | 33 +++++- 2 files changed, 102 insertions(+), 38 deletions(-) diff --git a/apps/cyberstorm-remix/app/settings/user/Account/Account.tsx b/apps/cyberstorm-remix/app/settings/user/Account/Account.tsx index 6c65a6fbe..2af2d6a7e 100644 --- a/apps/cyberstorm-remix/app/settings/user/Account/Account.tsx +++ b/apps/cyberstorm-remix/app/settings/user/Account/Account.tsx @@ -1,12 +1,17 @@ import { faTrashCan } from "@fortawesome/pro-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useStrongForm } from "cyberstorm/utils/StrongForm/useStrongForm"; +import { + NimbusErrorBoundary, + NimbusErrorBoundaryFallback, + type NimbusErrorBoundaryFallbackProps, +} from "cyberstorm/utils/errors/NimbusErrorBoundary"; import { useReducer } from "react"; import { useNavigate, useOutletContext, useRevalidator } from "react-router"; import { useHydrated } from "remix-utils/use-hydrated"; import { Loading } from "~/commonComponents/Loading/Loading"; import { NotLoggedIn } from "~/commonComponents/NotLoggedIn/NotLoggedIn"; -import { type OutletContextShape } from "~/root"; +import type { OutletContextShape } from "~/root"; import { NewAlert, @@ -15,8 +20,12 @@ import { NewTextInput, useToast, } from "@thunderstore/cyberstorm"; -import { UserFacingError, userDelete } from "@thunderstore/thunderstore-api"; +import { + UserFacingError, + formatUserFacingError, + userDelete, +} from "../../../../../../packages/thunderstore-api/src"; import "./Account.css"; export default function Account() { @@ -32,44 +41,70 @@ export default function Account() { } return ( -
-
-
-

Delete Account

-

- Delete your Thunderstore account permanently -

-
-
-
- - You are about to delete your account. Once deleted, it will be - gone forever. Please be certain. - -

- The mods that have been uploaded on this account will remain - public on the site even after deletion. If you need them to be - taken down as well, please contact an administrator on the - community Discord server. -
- - As a precaution, to delete your account, please input{" "} - - {outletContext.currentUser.username} - {" "} - into the field below. - + reset()} + > +

+
+
+

Delete Account

+

+ Delete your Thunderstore account permanently

-
- +
+
+
+ + You are about to delete your account. Once deleted, it will be + gone forever. Please be certain. + +

+ The mods that have been uploaded on this account will remain + public on the site even after deletion. If you need them to be + taken down as well, please contact an administrator on the + community Discord server. +
+ + As a precaution, to delete your account, please input{" "} + + {outletContext.currentUser.username} + {" "} + into the field below. + +

+
+ +
-
+ + ); +} + +/** + * Displays fallback messaging when the account settings view fails to render. + */ +function AccountSettingsFallback(props: NimbusErrorBoundaryFallbackProps) { + const { + title = "Account settings failed to load", + description = "Reload the account tab or return to settings.", + retryLabel = "Reload", + ...rest + } = props; + + return ( + ); } @@ -143,7 +178,7 @@ function DeleteAccountForm(props: { onSubmitError: (error) => { toast.addToast({ csVariant: "danger", - children: `Error occurred: ${error.message || "Unknown error"}`, + children: formatUserFacingError(error), duration: 8000, }); }, diff --git a/apps/cyberstorm-remix/app/settings/user/Settings.tsx b/apps/cyberstorm-remix/app/settings/user/Settings.tsx index da2f4e8cb..c1d2a819a 100644 --- a/apps/cyberstorm-remix/app/settings/user/Settings.tsx +++ b/apps/cyberstorm-remix/app/settings/user/Settings.tsx @@ -5,6 +5,11 @@ import { NewLink, Tabs } from "@thunderstore/cyberstorm"; import { type OutletContextShape } from "../../root"; import "./Settings.css"; +import { + NimbusErrorBoundary, + NimbusErrorBoundaryFallback, +} from "cyberstorm/utils/errors/NimbusErrorBoundary"; +import type { NimbusErrorBoundaryFallbackProps } from "cyberstorm/utils/errors/NimbusErrorBoundary"; export default function UserSettings() { const context = useOutletContext(); @@ -16,7 +21,10 @@ export default function UserSettings() { } return ( - <> + reset()} + > Settings @@ -47,6 +55,27 @@ export default function UserSettings() {
- + + ); +} + +/** + * Provides fallback messaging when the user settings shell fails to render. + */ +function UserSettingsFallback(props: NimbusErrorBoundaryFallbackProps) { + const { + title = "Settings failed to load", + description = "Reload the settings page or return to the dashboard.", + retryLabel = "Reload", + ...rest + } = props; + + return ( + ); }