46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { useEffect } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
/**
|
|
* Sentry smoke-test route — `/__test/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="mt-4 text-sm text-muted-foreground">{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";
|
|
}
|