Skip to content

Commit ff34007

Browse files
authored
docs(js/react-router): Document createSentryHandleError (#14565)
1 parent ac269b2 commit ff34007

File tree

1 file changed

+33
-10
lines changed
  • docs/platforms/javascript/guides/react-router

1 file changed

+33
-10
lines changed

docs/platforms/javascript/guides/react-router/index.mdx

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,11 @@ Update your `entry.server.tsx` file:
276276
+ createReadableStreamFromReadable,
277277
+});
278278

279-
export default handleRequest;
280-
281-
export const handleError: HandleErrorFunction = (error, { request }) => {
282-
// React Router may abort some interrupted requests, don't log those
283-
if (!request.signal.aborted) {
284-
+ Sentry.captureException(error);
285-
// optionally log the error so you can see it
286-
console.error(error);
287-
}
288-
};
279+
export default handleRequest;
289280

281+
+export const handleError = Sentry.createSentryHandleError({
282+
+ logErrors: false
283+
+});
290284

291285
// ... rest of your server entry
292286
```
@@ -369,6 +363,35 @@ export default wrapSentryHandleRequest(handleRequest);
369363

370364
</Expandable>
371365

366+
<Expandable title="Do you need to customize your handleError function?">
367+
If you have custom logic in your `handleError` function, you'll need to capture errors manually:
368+
369+
```tsx {12}
370+
import {
371+
getMetaTagTransformer,
372+
wrapSentryHandleRequest,
373+
} from "@sentry/react-router";
374+
// ... other imports
375+
376+
export function handleError(
377+
error: unknown,
378+
{
379+
request,
380+
params,
381+
context,
382+
}: LoaderFunctionArgs | ActionFunctionArgs
383+
) {
384+
if (!request.signal.aborted) {
385+
Sentry.captureException(error);
386+
console.error(formatErrorForJsonLogging(error));
387+
}
388+
}
389+
390+
// ... rest of your entry.server.ts file
391+
```
392+
393+
</Expandable>
394+
372395
### Update Scripts
373396

374397
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.

0 commit comments

Comments
 (0)