diff --git a/apps/client/src/pages/public/error.tsx b/apps/client/src/pages/public/error.tsx new file mode 100644 index 0000000000..e96ddf3148 --- /dev/null +++ b/apps/client/src/pages/public/error.tsx @@ -0,0 +1,64 @@ +// External libraries +import { Trans, t } from "@lingui/macro"; +import { Link, useRouteError } from "react-router"; +import { Button } from "@reactive-resume/ui"; +import { LocaleProvider } from "@/client/providers/locale"; + +type RouterError = { + status: number; + statusText?: string; + data: string; + message?: string; +} & Error; + +const getErrorMessage = (status: number) => { + switch (status) { + case 404: + return "The page you're looking for doesn't exist."; + case 403: + return "You don't have permission to access this page."; + case 500: + return "An internal server error occurred."; + case 401: + return "You are not authorized to access this page."; + case 400: + return "The request was invalid."; + default: + return "An unexpected error occurred."; + } +}; + +export const ErrorPage = () => { + const error = useRouteError() as RouterError; + + return ( + + + + + + {t`Error ${error.status}`} + + {error.statusText && {`${error.statusText}`}} + + + + {/* {error.data || error.message} */} + {error.data || error.message || getErrorMessage(error.status)} + + + + + + {t`Go to home`} + + + + + + + ); +}; diff --git a/apps/client/src/router/index.tsx b/apps/client/src/router/index.tsx index ea64965705..99fd390cf8 100644 --- a/apps/client/src/router/index.tsx +++ b/apps/client/src/router/index.tsx @@ -20,9 +20,10 @@ import { Providers } from "../providers"; import { AuthGuard } from "./guards/auth"; import { GuestGuard } from "./guards/guest"; import { authLoader } from "./loaders/auth"; +import { ErrorPage } from "../pages/public/error"; export const routes = createRoutesFromElements( - }> + } errorElement={}> }> } />
+ {/* {error.data || error.message} */} + {error.data || error.message || getErrorMessage(error.status)} +