Skip to content

docs(js/react-router): Document createSentryHandleError #14565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions docs/platforms/javascript/guides/react-router/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -369,6 +363,35 @@ export default wrapSentryHandleRequest(handleRequest);

</Expandable>

<Expandable title="Do you need to customize your handleError function?">
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
```

</Expandable>

### 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.
Expand Down