Skip to content

Commit 43c5387

Browse files
committed
docs: added error reporting
1 parent 11ae512 commit 43c5387

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

docs/how-to/error-boundary.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { Route } from "./+types/root";
2222
export function ErrorBoundary({
2323
error,
2424
}: Route.ErrorBoundaryProps) {
25-
console.error(error);
2625
if (isRouteErrorResponse(error)) {
2726
return (
2827
<>

docs/how-to/error-reporting.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
11
---
22
title: Error Reporting
3-
hidden: true
43
---
4+
5+
# Error Reporting
6+
7+
React Router catches errors in your route modules and sends them to [error boundaries](./error-boundary) to prevent blank pages when errors occur. However, ErrorBoundary isn't sufficient for logging and reporting errors. To access these caught errors, use the handleError export of the server entry module.
8+
9+
## 1. Reveal the server entry
10+
11+
If you don't see `entry.server.tsx` in your app directory, you're using a default entry. Reveal it with this cli command:
12+
13+
```shellscript nonumber
14+
react-router reveal
15+
```
16+
17+
## 2. Export your error handler
18+
19+
This function is called whenever React Router catches an error in your application on the server.
20+
21+
```tsx filename=entry.server.tsx
22+
import { type HandleErrorFunction } from "react-router";
23+
24+
export const handleError: HandleErrorFunction = (
25+
error,
26+
{ request }
27+
) => {
28+
// React Router may abort some interrupted requests, don't log those
29+
if (!request.signal.aborted) {
30+
myReportError(error);
31+
32+
// make sure to still log the error so you can see it
33+
console.error(error);
34+
}
35+
};
36+
```

0 commit comments

Comments
 (0)