Skip to content

Commit f2df8f7

Browse files
global error handler file.
1 parent 059f67e commit f2df8f7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

utils/globalErrorhandler.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
};

0 commit comments

Comments
 (0)