Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/__test.client-throw.tsx
T

49 lines
1.7 KiB
TypeScript

import type { LoaderFunctionArgs } from "react-router";
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
/**
* Sentry smoke-test route — `/client-throw`.
*
* The `__test` filename segment is pathless under the v1 compatibility route
* convention; the public diagnostic URL therefore starts at `client-throw`.
*
* Only available in non-production builds OR when SENTRY_TEST_ROUTES=true
* is set on the SSR runtime. The loader returns a 404 in production so
* this route cannot be used as a DoS lever in a live deployment.
*
* Usage:
* 1. Build + deploy with SENTRY_TEST_ROUTES=true on staging.
* 2. Open the URL in a browser — the component will throw synchronously
* during render, the React-Router root ErrorBoundary catches it and
* Sentry.captureException reports the error.
*
* @see docs/improvement-plan/02-observability/sentry-wiring-web.md (Step 11)
*/
export async function loader({}: LoaderFunctionArgs) {
if (!testRoutesEnabled()) {
throw new Response(null, { status: 404 });
}
return new Response(null, { status: 200 });
}
export default function ClientThrow() {
const { t } = useTranslation();
useEffect(() => {
throw new Error("phase-02-sentry-smoke: client-side throw");
}, []);
return (
<div className="mx-auto p-12 text-center">
<h1 className="text-2xl font-bold">{t("diagnostics.sentry.clientSmoke.title")}</h1>
<p className="text-muted-foreground mt-4 text-sm">{t("diagnostics.sentry.clientSmoke.description")}</p>
</div>
);
}
function testRoutesEnabled(): boolean {
if (typeof process === "undefined") return false;
if (process.env.NODE_ENV !== "production") return true;
return process.env.SENTRY_TEST_ROUTES === "true";
}