diff --git a/docs/platforms/javascript/guides/react-router/index.mdx b/docs/platforms/javascript/guides/react-router/index.mdx index 91b6856662666..c3f341c9b2281 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 have custom logic in 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.