Skip to content

Commit 6314587

Browse files
authored
Add custom error page (#1181)
## Description <!-- Please provide a brief description of the changes made in this pull request. Include any relevant context or reasoning for the changes. --> Adds a page for **uncaught errors**, allowing users to refresh or go home. This replaces the default we've had since the start of the app. ## Related Issue and Pull requests <!-- Link to any related issues using the format #<issue-number> --> ## Type of Change <!-- Please delete options that are not relevant --> - [x] Improvement ## Checklist <!-- Please ensure the following are completed before submitting the PR --> - [ ] I have tested this does not break current pipelines / runs functionality - [ ] I have tested the changes on staging ## Screenshots (if applicable) <!-- Include any screenshots that might help explain the changes or provide visual context --> ![image.png](https://app.graphite.dev/user-attachments/assets/c5fdf00d-33e9-4d39-a841-ce588fa048c1.png) ## Test Instructions <!-- Detail steps and prerequisites for testing the changes in this PR --> You can force an uncaught error (e.g. a missing provider) ## Additional Comments <!-- Add any additional context or information that reviewers might need to know regarding this PR -->
1 parent 95f54cb commit 6314587

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

src/components/ui/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const blockStackVariants = cva("flex flex-col w-full", {
3232
"2": "gap-2",
3333
"3": "gap-3",
3434
"4": "gap-4",
35+
"8": "gap-8",
3536
},
3637
},
3738
});

src/components/ui/typography.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const textVariants = cva("", {
3636
sm: "text-sm",
3737
md: "text-md",
3838
lg: "text-lg",
39+
xl: "text-xl",
40+
"2xl": "text-2xl",
3941
},
4042
weight: {
4143
regular: "font-regular",

src/routes/ErrorPage.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useRouter } from "@tanstack/react-router";
2+
import { type ErrorComponentProps } from "@tanstack/react-router";
3+
import { useCallback } from "react";
4+
5+
import { InfoBox } from "@/components/shared/InfoBox";
6+
import { Button } from "@/components/ui/button";
7+
import { BlockStack } from "@/components/ui/layout";
8+
import { Paragraph, Text } from "@/components/ui/typography";
9+
10+
export default function ErrorPage({ error, reset }: ErrorComponentProps) {
11+
const router = useRouter();
12+
13+
const handleRefresh = useCallback(() => {
14+
if (reset) {
15+
reset();
16+
} else {
17+
window.location.reload();
18+
}
19+
}, [reset]);
20+
21+
const handleGoHome = useCallback(() => {
22+
router.navigate({ to: "/" });
23+
}, [router]);
24+
25+
return (
26+
<div className="min-h-screen flex items-center justify-center bg-background p-4">
27+
<div className="max-w-xs w-full">
28+
<BlockStack gap="8" align="center">
29+
<BlockStack gap="2" align="center">
30+
<Text size="2xl" weight="bold">
31+
Something went wrong
32+
</Text>
33+
<Paragraph tone="subdued" size="sm">
34+
An unexpected error occurred.
35+
</Paragraph>
36+
</BlockStack>
37+
38+
<InfoBox title="Error Details" variant="error">
39+
<Paragraph font="mono" size="xs">
40+
{error?.message || "An unexpected error occurred"}
41+
</Paragraph>
42+
</InfoBox>
43+
44+
<BlockStack gap="3">
45+
<Button onClick={handleRefresh} className="w-full">
46+
Try Again
47+
</Button>
48+
49+
<Button
50+
onClick={handleGoHome}
51+
variant="secondary"
52+
className="w-full"
53+
>
54+
Go Home
55+
</Button>
56+
</BlockStack>
57+
</BlockStack>
58+
</div>
59+
</div>
60+
);
61+
}

src/routes/router.ts

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

1212
import RootLayout from "../components/layout/RootLayout";
1313
import Editor from "./Editor";
14+
import ErrorPage from "./ErrorPage";
1415
import Home from "./Home";
1516
import PipelineRun from "./PipelineRun";
1617
import { QuickStartPage } from "./QuickStart";
@@ -35,6 +36,7 @@ export const APP_ROUTES = {
3536

3637
const rootRoute = createRootRoute({
3738
component: Outlet,
39+
errorComponent: ErrorPage,
3840
});
3941

4042
const mainLayout = createRoute({

0 commit comments

Comments
 (0)