Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
import Bugsnag, { type Event } from "@bugsnag/js";
import { type ErrorComponentProps, useRouter } from "@tanstack/react-router";
import { useEffect } from "react";

import { InfoBox } from "@/components/shared/InfoBox";
import { Button } from "@/components/ui/button";
import { BlockStack } from "@/components/ui/layout";
import { Paragraph, Text } from "@/components/ui/typography";
import { isBugsnagEnabled } from "@/services/errorManagement/bugsnag";

export default function ErrorPage({ error }: ErrorComponentProps) {
const ERROR_HANDLER_METADATA_KEY = "error_handler";

export const ErrorPage = ({ error, reset = () => {} }: ErrorComponentProps) => {
const router = useRouter();

useEffect(() => {
if (isBugsnagEnabled() && error instanceof Error) {
Bugsnag.notify(error, (event: Event) => {
event.addMetadata(ERROR_HANDLER_METADATA_KEY, {
pathname: window.location.pathname,
});
});
}
}, [error]);

const handleRefresh = () => {
reset();
window.location.reload();
};

const handleGoHome = () => {
reset();
router.navigate({ to: "/" });
};

const errorMessage =
error instanceof Error ? error.message : "An unexpected error occurred";

return (
<div className="min-h-screen flex items-center justify-center bg-background p-4">
<div className="max-w-xs w-full">
Expand All @@ -31,7 +51,7 @@ export default function ErrorPage({ error }: ErrorComponentProps) {

<InfoBox title="Error Details" variant="error">
<Paragraph font="mono" size="xs">
{error?.message || "An unexpected error occurred"}
{errorMessage}
</Paragraph>
</InfoBox>

Expand All @@ -52,4 +72,4 @@ export default function ErrorPage({ error }: ErrorComponentProps) {
</div>
</div>
);
}
};
2 changes: 1 addition & 1 deletion src/routes/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
Outlet,
} from "@tanstack/react-router";

import { ErrorPage } from "@/components/shared/ErrorPage";
import { AuthorizationResultScreen as GitHubAuthorizationResultScreen } from "@/components/shared/GitHubAuth/AuthorizationResultScreen";
import { AuthorizationResultScreen as HuggingFaceAuthorizationResultScreen } from "@/components/shared/HuggingFaceAuth/AuthorizationResultScreen";
import { BASE_URL, IS_GITHUB_PAGES } from "@/utils/constants";

import RootLayout from "../components/layout/RootLayout";
import Editor from "./Editor";
import ErrorPage from "./ErrorPage";
import Home from "./Home";
import NotFoundPage from "./NotFoundPage";
import PipelineRun from "./PipelineRun";
Expand Down
2 changes: 2 additions & 0 deletions src/services/errorManagement/bugsnag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const BUGSNAG_CUSTOM_GROUPING_KEY = import.meta.env

const GENERIC_ERROR_CLASS = "Error";

export const isBugsnagEnabled = (): boolean => Boolean(BUGSNAG_API_KEY);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be written like:

export const IS_BUGSNAG_ENABLED = Boolean(BUGSNAG_API_KEY);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! Changed


const getBugsnagConfig = (): BrowserConfig => {
return {
apiKey: BUGSNAG_API_KEY,
Expand Down