File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Bugsnag from "@bugsnag/js" ;
2+ import React , { type ReactNode } from "react" ;
3+
4+ import { ErrorHandler } from "@/components/shared/ErrorHandler" ;
5+ import { getBugsnagConfig } from "@/services/errorManagement/bugsnag" ;
6+
7+ interface ErrorBoundaryProps {
8+ children : ReactNode ;
9+ }
10+
11+ /**
12+ * Generic ErrorBoundary that determines which error reporting service to use.
13+ * Currently supports Bugsnag, but can be extended to support other services.
14+ */
15+ export const ErrorBoundary = ( { children } : ErrorBoundaryProps ) => {
16+ const bugsnagConfig = getBugsnagConfig ( ) ;
17+
18+ // Use Bugsnag's ErrorBoundary if enabled
19+ if ( bugsnagConfig . enabled ) {
20+ const BugsnagBoundary = Bugsnag . getPlugin ( "react" ) ! . createErrorBoundary (
21+ React ,
22+ ) ;
23+
24+ return (
25+ < BugsnagBoundary
26+ FallbackComponent = { ( props : {
27+ error : Error ;
28+ info : React . ErrorInfo ;
29+ clearError : ( ) => void ;
30+ } ) => (
31+ < ErrorHandler
32+ error = { props . error }
33+ errorType = "app_error_boundary"
34+ resetErrorBoundary = { props . clearError }
35+ />
36+ ) }
37+ >
38+ { children }
39+ </ BugsnagBoundary >
40+ ) ;
41+ }
42+
43+ // Fallback: no error boundary (just render children)
44+ // In the future, this could check for other error reporting services
45+ return < > { children } </ > ;
46+ } ;
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ import { StrictMode } from "react";
77import ReactDOM from "react-dom/client" ;
88import { scan } from "react-scan" ;
99
10+ import { ErrorBoundary } from "@/components/shared/ErrorBoundary" ;
11+
1012import { router } from "./routes/router" ;
1113
1214const queryClient = new QueryClient ( ) ;
@@ -22,9 +24,11 @@ if (!rootElement.innerHTML) {
2224 const root = ReactDOM . createRoot ( rootElement ) ;
2325 root . render (
2426 < StrictMode >
25- < QueryClientProvider client = { queryClient } >
26- < RouterProvider router = { router } />
27- </ QueryClientProvider >
27+ < ErrorBoundary >
28+ < QueryClientProvider client = { queryClient } >
29+ < RouterProvider router = { router } />
30+ </ QueryClientProvider >
31+ </ ErrorBoundary >
2832 </ StrictMode > ,
2933 ) ;
3034}
You can’t perform that action at this time.
0 commit comments