@@ -44,93 +44,6 @@ export default function RootLayout() {
4444 SpaceMono : require ( '../assets/fonts/SpaceMono-Regular.ttf' ) ,
4545 } )
4646
47- // Add global error handlers directly in the React component
48- useEffect ( ( ) => {
49- // Direct error handler for promise rejections
50- const errorHandler = ( error : any ) => {
51- console . log ( '[RootLayout] Caught unhandled error:' , error )
52- if ( error instanceof Error ) {
53- LDObserve . recordError ( error , {
54- 'error.unhandled' : true ,
55- 'error.caught_by' : 'root_component_handler' ,
56- } )
57- }
58- }
59-
60- // Register a direct listener for unhandled rejections at the app level
61- const rejectionHandler = ( event : any ) => {
62- const error = event . reason || new Error ( 'Unknown promise rejection' )
63- console . log (
64- '[RootLayout] Caught unhandled promise rejection:' ,
65- error ,
66- )
67- LDObserve . recordError (
68- error instanceof Error ? error : new Error ( String ( error ) ) ,
69- {
70- 'error.unhandled' : true ,
71- 'error.caught_by' : 'root_component_promise_handler' ,
72- 'promise.handled' : false ,
73- } ,
74- )
75- }
76-
77- // Network error handler to catch fetch errors
78- const networkErrorHandler = ( error : any ) => {
79- console . log ( '[RootLayout] Caught network error:' , error )
80- LDObserve . recordError (
81- error instanceof Error ? error : new Error ( String ( error ) ) ,
82- {
83- 'error.unhandled' : true ,
84- 'error.caught_by' : 'root_component_network_handler' ,
85- 'error.type' : 'network' ,
86- } ,
87- )
88- }
89-
90- // Set up the handlers
91- if ( global . ErrorUtils ) {
92- const originalGlobalHandler = global . ErrorUtils . getGlobalHandler ( )
93- global . ErrorUtils . setGlobalHandler ( ( error , isFatal ) => {
94- errorHandler ( error )
95- if ( originalGlobalHandler ) {
96- originalGlobalHandler ( error , isFatal )
97- }
98- } )
99- }
100-
101- // React Native doesn't fully support the standard addEventListener API for unhandledrejection
102- // This is a workaround using Promise patches
103- const originalPromiseReject = Promise . reject
104- Promise . reject = function ( reason ) {
105- const result = originalPromiseReject . call ( this , reason )
106- setTimeout ( ( ) => {
107- // If the rejection isn't handled in the next tick, report it
108- if ( ! result . _handled ) {
109- rejectionHandler ( { reason } )
110- }
111- } , 0 )
112- return result
113- }
114-
115- // Patch fetch to catch network errors
116- const originalFetch = global . fetch
117- global . fetch = function ( ...args ) {
118- return originalFetch . apply ( this , args ) . catch ( ( error ) => {
119- networkErrorHandler ( error )
120- throw error // re-throw to preserve original behavior
121- } )
122- } as typeof fetch
123-
124- return ( ) => {
125- // Cleanup if component unmounts (unlikely for root layout)
126- if ( global . ErrorUtils && originalGlobalHandler ) {
127- global . ErrorUtils . setGlobalHandler ( originalGlobalHandler )
128- }
129- Promise . reject = originalPromiseReject
130- global . fetch = originalFetch
131- }
132- } , [ ] )
133-
13447 useEffect ( ( ) => {
13548 if ( loaded ) {
13649 SplashScreen . hideAsync ( )
0 commit comments