Skip to content

Commit 874b480

Browse files
committed
Log errors in RouteErrorBoundary to Sentry
Using captureRemixErrorBoundaryError() is what Sentry's docs recommend for Remix, so that approach was chosen here. Remix provides handleError approach, but their docs apply it only on server side (as we do in entry.server.tsx), so it wasn't applied here.
1 parent 6e2d678 commit 874b480

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

apps/cyberstorm-remix/app/commonComponents/ErrorBoundary/RouteErrorBoundary.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { JSX } from "react";
1+
import { useEffect, type JSX } from "react";
22
import { isRouteErrorResponse, useRouteError } from "react-router";
3+
import { captureRemixErrorBoundaryError } from "@sentry/remix";
34

45
import { ApiError } from "@thunderstore/thunderstore-api";
56

@@ -15,6 +16,17 @@ type StatusCode = number | "???";
1516
export function RouteErrorBoundary() {
1617
const error = useRouteError();
1718

19+
// Seeing double console logs caused by React's strictMode (that
20+
// *should* happen only in dev mode) makes me want to ensure any
21+
// rerenders don't get logged in Sentry twice.
22+
useEffect(() => {
23+
if (error && import.meta.env.PROD) {
24+
captureRemixErrorBoundaryError(error);
25+
} else if (error) {
26+
console.error("Error boundary caught error", error);
27+
}
28+
}, [error]);
29+
1830
let statusCode: StatusCode = "???";
1931

2032
if (isRouteErrorResponse(error)) {

apps/cyberstorm-remix/docs/error-boundary.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export { RouteErrorBoundary as ErrorBoundary } from "app/commonComponents/ErrorB
1616

1717
- Consider replacing the error boundary in `root.tsx` with this one
1818
- Use `RouteErrorBoundary` in route components
19-
- Investigate if [error reporting](https://reactrouter.com/how-to/error-reporting) (via Sentry) should be done separately or implement as a part of the error boundary
2019
- Add "retry buttons" (e.g. reloading the page on 500 series of errors)
2120
- As `RouteErrorBoundary` is all-or-nothing solution when it comes to rendering, consider if there's a need for more granular non-route component level error boundaries. We might not need or want to use them, as error boundaries are intended more for render time errors, and any errors caused by user interaction should be handled by the component logic itself
2221
- If it turns out we don't want other error boundaries, consider renaming `RouteErrorBoundary` to just `ErrorBoundary`

0 commit comments

Comments
 (0)