File tree Expand file tree Collapse file tree 4 files changed +45
-15
lines changed Expand file tree Collapse file tree 4 files changed +45
-15
lines changed Original file line number Diff line number Diff line change 1515 },
1616 "extends": ["eslint:recommended", "plugin:react/recommended"],
1717 "rules": {
18- "react-native/split-platform-components": 2,
1918 "react/no-did-mount-set-state": 2,
2019 "react/no-did-update-set-state": 2,
2120 "react/no-direct-mutation-state": 2,
Original file line number Diff line number Diff line change 1+ import { Alert } from 'react-native' ;
2+ import { BackAndroid } from 'react-native' ;
3+ import { setJSExceptionHandler } from 'react-native-exception-handler' ;
4+
5+ const reporter = ( error ) => {
6+ // Logic for reporting to devs
7+ // Example : Log issues to github issues using github apis.
8+ console . log ( error ) ; // sample
9+ } ;
10+
11+ const errorHandler = ( e , isFatal ) => {
12+ if ( isFatal ) {
13+ reporter ( e ) ;
14+ Alert . alert (
15+ 'Unexpected error occurred' ,
16+ `
17+ Error: ${ ( isFatal ) ? 'Fatal:' : '' } ${ e . name } ${ e . message }
18+
19+ We have reported this to our team ! Please close the app and start again!
20+ ` ,
21+ [ {
22+ text : 'Close' ,
23+ onPress : ( ) => {
24+ BackAndroid . exitApp ( ) ;
25+ }
26+ } ]
27+ ) ;
28+ } else {
29+ console . log ( e ) ; // So that we can see it in the ADB logs in case of Android if needed
30+ }
31+ } ;
32+
33+ setJSExceptionHandler ( errorHandler ) ;
Original file line number Diff line number Diff line change 11import { Alert } from 'react-native' ;
2+ import RNRestart from 'react-native-restart' ;
3+ import { setJSExceptionHandler } from 'react-native-exception-handler' ;
24
35const errorHandler = ( e , isFatal ) => {
46 if ( isFatal ) {
@@ -12,7 +14,7 @@ const errorHandler = (e, isFatal) => {
1214 [ {
1315 text : 'Restart' ,
1416 onPress : ( ) => {
15- console . log ( 'test' ) ;
17+ RNRestart . Restart ( ) ;
1618 }
1719 } ]
1820 ) ;
@@ -21,4 +23,4 @@ const errorHandler = (e, isFatal) => {
2123 }
2224} ;
2325
24- export default errorHandler ;
26+ setJSExceptionHandler ( errorHandler ) ;
Original file line number Diff line number Diff line change 1- import errorHandler from './errorHandler' ;
1+ const noop = ( ) => { } ;
22
3- export const handleExceptions = ( allowedInDevMode = false ) => {
4- registerErrorHandler ( errorHandler , allowedInDevMode ) ;
5- } ;
6-
7- export const registerErrorHandler = ( customHandler , allowedInDevMode = false ) => {
3+ export const setJSExceptionHandler = ( customHandler = noop , allowedInDevMode = false ) => {
84 const allowed = allowedInDevMode ? true : ! __DEV__ ;
95 if ( allowed ) {
10- if ( customHandler ) {
11- global . ErrorUtils . setGlobalHandler ( customHandler ) ;
12- } else {
13- console . log ( 'Custom Error Handler not passed to registerErrorHandler' ) ;
14- }
6+ global . ErrorUtils . setGlobalHandler ( customHandler ) ;
157 } else {
16- console . log ( 'Not registering the error handler since its in dev mode and allowedInDevMode is not true ' ) ;
8+ console . log ( 'Skipping setJSExceptionHandler: Reason: In DEV mode and allowedInDevMode = false ' ) ;
179 }
1810} ;
11+
12+ export default {
13+ setJSExceptionHandler
14+ } ;
You can’t perform that action at this time.
0 commit comments