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 {
2+ setJSExceptionHandler ,
3+ setNativeExceptionHandler ,
4+ } from "react-native-exception-handler" ;
5+ import { Alert } from "react-native" ;
6+ import { reportError } from "../services/errorReporting.service" ;
7+
8+ // JavaScript Error Handler
9+ export const setupGlobalErrorHandlers = ( ) => {
10+ setJSExceptionHandler ( ( error , isFatal ) => {
11+ // Report the error using your actual reportError function
12+ reportError ( error , { isFatal } ) ;
13+
14+ // Show a friendly message instead of crashing
15+ Alert . alert (
16+ "Unexpected Error Occurred" ,
17+ "We encountered an issue. The app will continue running, and our team has been notified." ,
18+ [ { text : "OK" } ]
19+ ) ;
20+ } , true ) ;
21+
22+ // Native Exception Handler
23+ setNativeExceptionHandler (
24+ ( exceptionString ) => {
25+ // This is called when native code throws an exception
26+ const error = new Error ( `Native Exception: ${ exceptionString } ` ) ;
27+ reportError ( error , { isFatal : true } ) ;
28+ } ,
29+ false , // don't force app to quit
30+ true // should catch all exceptions
31+ ) ;
32+ } ;
You can’t perform that action at this time.
0 commit comments