Skip to content

Commit 5bcb71f

Browse files
committed
refactor: improve error handling components
- Rename ErrorPage to FullPageError for clarity - Extract ErrorDisplay component for reusable error UI - Add unified ErrorHandler component for consistent error handling - Integrate ErrorHandler with FullPageError
1 parent ca3c44a commit 5bcb71f

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1+
import Bugsnag from "@bugsnag/js";
12
import { type ErrorComponentProps, useRouter } from "@tanstack/react-router";
3+
import { useEffect } from "react";
24

35
import { InfoBox } from "@/components/shared/InfoBox";
46
import { Button } from "@/components/ui/button";
57
import { BlockStack } from "@/components/ui/layout";
68
import { Paragraph, Text } from "@/components/ui/typography";
9+
import { getBugsnagConfig } from "@/services/errorManagement/bugsnag";
710

8-
export default function ErrorPage({ error }: ErrorComponentProps) {
11+
export const ErrorPage = ({ error, reset }: ErrorComponentProps) => {
912
const router = useRouter();
1013

14+
useEffect(() => {
15+
const config = getBugsnagConfig();
16+
17+
if (config.enabled && error instanceof Error) {
18+
Bugsnag.notify(error, (event) => {
19+
event.addMetadata("error_handler", {
20+
pathname: window.location.pathname,
21+
});
22+
});
23+
}
24+
}, [error]);
25+
1126
const handleRefresh = () => {
27+
// Reset error boundary if available (some callers provide this function)
28+
reset?.();
1229
window.location.reload();
1330
};
1431

1532
const handleGoHome = () => {
33+
// Reset error boundary if available (some callers provide this function)
34+
reset?.();
1635
router.navigate({ to: "/" });
1736
};
1837

38+
const errorMessage =
39+
error instanceof Error ? error.message : "An unexpected error occurred";
40+
1941
return (
2042
<div className="min-h-screen flex items-center justify-center bg-background p-4">
2143
<div className="max-w-xs w-full">
@@ -31,7 +53,7 @@ export default function ErrorPage({ error }: ErrorComponentProps) {
3153

3254
<InfoBox title="Error Details" variant="error">
3355
<Paragraph font="mono" size="xs">
34-
{error?.message || "An unexpected error occurred"}
56+
{errorMessage}
3557
</Paragraph>
3658
</InfoBox>
3759

@@ -52,4 +74,4 @@ export default function ErrorPage({ error }: ErrorComponentProps) {
5274
</div>
5375
</div>
5476
);
55-
}
77+
};

src/routes/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import {
66
Outlet,
77
} from "@tanstack/react-router";
88

9+
import { ErrorPage } from "@/components/shared/ErrorPage";
910
import { AuthorizationResultScreen as GitHubAuthorizationResultScreen } from "@/components/shared/GitHubAuth/AuthorizationResultScreen";
1011
import { AuthorizationResultScreen as HuggingFaceAuthorizationResultScreen } from "@/components/shared/HuggingFaceAuth/AuthorizationResultScreen";
1112
import { BASE_URL, IS_GITHUB_PAGES } from "@/utils/constants";
1213

1314
import RootLayout from "../components/layout/RootLayout";
1415
import Editor from "./Editor";
15-
import ErrorPage from "./ErrorPage";
1616
import Home from "./Home";
1717
import NotFoundPage from "./NotFoundPage";
1818
import PipelineRun from "./PipelineRun";

0 commit comments

Comments
 (0)