Skip to content

Commit e438602

Browse files
committed
fix(errorpage): added localProvider, replaced a with Link and added custom messages
- Add LocaleProvider wrapper for i18n support - Replace a tag with React Router Link components - Add custom error messages for different HTTP status codes - Implement proper translation support using Trans and t components
1 parent f42b29e commit e438602

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed
Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { useRouteError } from "react-router";
1+
// External libraries
2+
import { Trans, t } from "@lingui/macro";
3+
import { Link, useRouteError } from "react-router";
24
import { Button } from "@reactive-resume/ui";
5+
import { LocaleProvider } from "@/client/providers/locale";
36

47
type RouterError = {
58
status: number;
@@ -8,34 +11,54 @@ type RouterError = {
811
message?: string;
912
} & Error;
1013

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+
1131
export const ErrorPage = () => {
1232
const error = useRouteError() as RouterError;
1333

1434
return (
15-
<main className="flex items-center justify-center min-h-screen p-4">
16-
<div className="w-full max-w-sm space-y-6">
17-
<h4 className="flex flex-col text-4xl font-bold text-white">
18-
<span>
19-
Error {error.status}
20-
</span>
21-
{error.statusText && <span className="text-base font-normal">{error.statusText}</span>}
22-
</h4>
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>
2344

24-
<p className="text-sm text-gray-500 break-words">
25-
{error.data || error.message}
26-
</p>
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>
2749

28-
<div className="pt-2">
29-
<a
30-
href={process.env.PUBLIC_URL}
31-
className="inline-block"
32-
>
33-
<Button>
34-
Go to home
35-
</Button>
36-
</a>
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>
3760
</div>
38-
</div>
39-
</main>
61+
</main>
62+
</LocaleProvider>
4063
);
4164
};

0 commit comments

Comments
 (0)