File tree Expand file tree Collapse file tree 2 files changed +66
-1
lines changed
Expand file tree Collapse file tree 2 files changed +66
-1
lines changed Original file line number Diff line number Diff line change 1+ // External libraries
2+ import { Trans , t } from "@lingui/macro" ;
3+ import { Link , useRouteError } from "react-router" ;
4+ import { Button } from "@reactive-resume/ui" ;
5+ import { LocaleProvider } from "@/client/providers/locale" ;
6+
7+ type RouterError = {
8+ status : number ;
9+ statusText ?: string ;
10+ data : string ;
11+ message ?: string ;
12+ } & Error ;
13+
14+ const getErrorMessage = ( status : number ) => {
15+ switch ( status ) {
16+ case 404 :
17+ return "The page you're looking for doesn't exist." ;
18+ case 403 :
19+ return "You don't have permission to access this page." ;
20+ case 500 :
21+ return "An internal server error occurred." ;
22+ case 401 :
23+ return "You are not authorized to access this page." ;
24+ case 400 :
25+ return "The request was invalid." ;
26+ default :
27+ return "An unexpected error occurred." ;
28+ }
29+ } ;
30+
31+ export const ErrorPage = ( ) => {
32+ const error = useRouteError ( ) as RouterError ;
33+
34+ return (
35+ < LocaleProvider >
36+ < main className = "flex items-center justify-center min-h-screen p-4" >
37+ < div className = "w-full max-w-sm space-y-6" >
38+ < h4 className = "flex flex-col text-4xl font-bold text-white" >
39+ < span >
40+ { t `Error ${ error . status } ` }
41+ </ span >
42+ { error . statusText && < span className = "text-base font-normal" > { `${ error . statusText } ` } </ span > }
43+ </ h4 >
44+
45+ < p className = "text-sm text-gray-500 break-words" >
46+ { /* {error.data || error.message} */ }
47+ < Trans > { error . data || error . message || getErrorMessage ( error . status ) } </ Trans >
48+ </ p >
49+
50+ < div className = "pt-2" >
51+ < Link
52+ to = "/"
53+ className = "inline-block"
54+ >
55+ < Button >
56+ { t `Go to home` }
57+ </ Button >
58+ </ Link >
59+ </ div >
60+ </ div >
61+ </ main >
62+ </ LocaleProvider >
63+ ) ;
64+ } ;
Original file line number Diff line number Diff line change @@ -20,9 +20,10 @@ import { Providers } from "../providers";
2020import { AuthGuard } from "./guards/auth" ;
2121import { GuestGuard } from "./guards/guest" ;
2222import { authLoader } from "./loaders/auth" ;
23+ import { ErrorPage } from "../pages/public/error" ;
2324
2425export const routes = createRoutesFromElements (
25- < Route element = { < Providers /> } >
26+ < Route element = { < Providers /> } errorElement = { < ErrorPage /> } >
2627 < Route element = { < HomeLayout /> } >
2728 < Route path = "/" element = { < HomePage /> } />
2829 </ Route >
You can’t perform that action at this time.
0 commit comments