From 1ab3b3fcb003f63c7fba856ce1d58da3340147c1 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Wed, 6 Aug 2025 10:24:30 +0200 Subject: [PATCH 1/2] document createSentryHandleError --- .../javascript/guides/react-router/index.mdx | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/docs/platforms/javascript/guides/react-router/index.mdx b/docs/platforms/javascript/guides/react-router/index.mdx index 91b6856662666..b98994e5dd04e 100644 --- a/docs/platforms/javascript/guides/react-router/index.mdx +++ b/docs/platforms/javascript/guides/react-router/index.mdx @@ -276,17 +276,11 @@ Update your `entry.server.tsx` file: + createReadableStreamFromReadable, +}); -export default handleRequest; - -export const handleError: HandleErrorFunction = (error, { request }) => { - // React Router may abort some interrupted requests, don't log those - if (!request.signal.aborted) { -+ Sentry.captureException(error); - // optionally log the error so you can see it - console.error(error); - } -}; + export default handleRequest; ++export const handleError = Sentry.createSentryHandleError({ ++ logErrors: false ++}); // ... rest of your server entry ``` @@ -369,6 +363,35 @@ export default wrapSentryHandleRequest(handleRequest); + + If you need to update the logic of your `handleError` function you'll need to capture errors manually: + +```tsx {12} +import { + getMetaTagTransformer, + wrapSentryHandleRequest, +} from "@sentry/react-router"; +// ... other imports + +export function handleError( + error: unknown, + { + request, + params, + context, + }: LoaderFunctionArgs | ActionFunctionArgs +) { + if (!request.signal.aborted) { + Sentry.captureException(error); + console.error(formatErrorForJsonLogging(error)); + } +} + +// ... rest of your entry.server.ts file +``` + + + ### Update Scripts Since React Router is running in ESM mode, you need to use the `--import` command line options to load our server-side instrumentation module before the application starts. From b49ba945b99ffc8fca97f546fd953ffc33247054 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 7 Aug 2025 14:07:52 +0200 Subject: [PATCH 2/2] Update docs/platforms/javascript/guides/react-router/index.mdx Co-authored-by: Andrei <168741329+andreiborza@users.noreply.github.com> --- docs/platforms/javascript/guides/react-router/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/javascript/guides/react-router/index.mdx b/docs/platforms/javascript/guides/react-router/index.mdx index b98994e5dd04e..c3f341c9b2281 100644 --- a/docs/platforms/javascript/guides/react-router/index.mdx +++ b/docs/platforms/javascript/guides/react-router/index.mdx @@ -364,7 +364,7 @@ export default wrapSentryHandleRequest(handleRequest); - If you need to update the logic of your `handleError` function you'll need to capture errors manually: + If you have custom logic in your `handleError` function, you'll need to capture errors manually: ```tsx {12} import {