import { Link, rootRouteId, useMatch, useRouter } from "@tanstack/react-router"; import type { ErrorComponentProps } from "@tanstack/react-router"; import * as React from "react"; import { shouldCaptureAppErrorCode } from "@/shared/error-codes"; import { getErrorCode, getStandardErrorMessage, } from "@/client/lib/error-messages"; import { AuthConfigErrorCard } from "@/client/components/AuthConfigErrorCard"; import { captureClientError } from "@/client/lib/posthog"; import { UnauthenticatedErrorCard } from "@/client/components/UnauthenticatedErrorCard"; export function DefaultCatchBoundary({ error }: ErrorComponentProps) { const router = useRouter(); const isRoot = useMatch({ strict: false, select: (state) => state.id === rootRouteId, }); const pathname = router.state.location.pathname; const message = getStandardErrorMessage( error, "Something went wrong. Please try again.", ); const errorCode = getErrorCode(error); React.useEffect(() => { if (!shouldCaptureAppErrorCode(errorCode)) { return; } captureClientError(error, { errorCode, path: pathname, }); }, [error, errorCode, pathname]); const showAuthConfigHelp = errorCode === "AUTH_CONFIG_MISSING"; const showSignInHelp = errorCode === "UNAUTHENTICATED"; if (showAuthConfigHelp) { return (
{ void router.invalidate(); }} />
); } if (showSignInHelp) { return (
{ void router.invalidate(); }} />
); } return (

{message}

{isRoot ? ( Home ) : ( { e.preventDefault(); window.history.back(); }} > Go Back )}
); }