Skip to content

Commit bedad4c

Browse files
committed
refactor: rename ErrorPage to FullPageError and extract ErrorDisplay
- Rename ErrorPage → FullPageError for clarity - Extract shared ErrorDisplay component from error pages - Update router to use FullPageError
1 parent 6cf38f9 commit bedad4c

3 files changed

Lines changed: 45 additions & 21 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import { type ErrorComponentProps, useRouter } from "@tanstack/react-router";
2-
31
import { InfoBox } from "@/components/shared/InfoBox";
42
import { Button } from "@/components/ui/button";
53
import { BlockStack } from "@/components/ui/layout";
64
import { Paragraph, Text } from "@/components/ui/typography";
75

8-
export default function ErrorPage({ error }: ErrorComponentProps) {
9-
const router = useRouter();
10-
11-
const handleRefresh = () => {
12-
window.location.reload();
13-
};
6+
interface ErrorDisplayProps {
7+
error: unknown;
8+
onRefresh: () => void;
9+
onGoHome: () => void;
10+
}
1411

15-
const handleGoHome = () => {
16-
router.navigate({ to: "/" });
17-
};
12+
/**
13+
* Shared error display component used by both ComponentError and FullPageError.
14+
* Shows a user-friendly error message with options to refresh or go home.
15+
*/
16+
export const ErrorDisplay = ({
17+
error,
18+
onRefresh,
19+
onGoHome,
20+
}: ErrorDisplayProps) => {
21+
const errorMessage =
22+
error instanceof Error ? error.message : "An unexpected error occurred";
1823

1924
return (
2025
<div className="min-h-screen flex items-center justify-center bg-background p-4">
@@ -31,25 +36,21 @@ export default function ErrorPage({ error }: ErrorComponentProps) {
3136

3237
<InfoBox title="Error Details" variant="error">
3338
<Paragraph font="mono" size="xs">
34-
{error?.message || "An unexpected error occurred"}
39+
{errorMessage}
3540
</Paragraph>
3641
</InfoBox>
3742

3843
<BlockStack gap="3">
39-
<Button onClick={handleRefresh} className="w-full">
44+
<Button onClick={onRefresh} className="w-full">
4045
Try Again
4146
</Button>
4247

43-
<Button
44-
onClick={handleGoHome}
45-
variant="secondary"
46-
className="w-full"
47-
>
48+
<Button onClick={onGoHome} variant="secondary" className="w-full">
4849
Go Home
4950
</Button>
5051
</BlockStack>
5152
</BlockStack>
5253
</div>
5354
</div>
5455
);
55-
}
56+
};

src/routes/FullPageError.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { type ErrorComponentProps, useRouter } from "@tanstack/react-router";
2+
3+
import { ErrorDisplay } from "@/components/shared/ErrorDisplay";
4+
5+
export default function FullPageError({ error }: ErrorComponentProps) {
6+
const router = useRouter();
7+
8+
const handleGoHome = () => {
9+
router.navigate({ to: "/" });
10+
};
11+
12+
const handleRefresh = () => {
13+
window.location.reload();
14+
};
15+
16+
return (
17+
<ErrorDisplay
18+
error={error}
19+
onRefresh={handleRefresh}
20+
onGoHome={handleGoHome}
21+
/>
22+
);
23+
}

src/routes/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { BASE_URL, IS_GITHUB_PAGES } from "@/utils/constants";
1212

1313
import RootLayout from "../components/layout/RootLayout";
1414
import Editor from "./Editor";
15-
import ErrorPage from "./ErrorPage";
15+
import FullPageError from "./FullPageError";
1616
import Home from "./Home";
1717
import NotFoundPage from "./NotFoundPage";
1818
import PipelineRun from "./PipelineRun";
@@ -40,7 +40,7 @@ export const APP_ROUTES = {
4040

4141
const rootRoute = createRootRoute({
4242
component: Outlet,
43-
errorComponent: ErrorPage,
43+
errorComponent: FullPageError,
4444
notFoundComponent: NotFoundPage,
4545
});
4646

0 commit comments

Comments
 (0)