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 15
15
},
16
16
"extends": ["eslint:recommended", "plugin:react/recommended"],
17
17
"rules": {
18
- "react-native/split-platform-components": 2,
19
18
"react/no-did-mount-set-state": 2,
20
19
"react/no-did-update-set-state": 2,
21
20
"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 1
1
import { Alert } from 'react-native' ;
2
+ import RNRestart from 'react-native-restart' ;
3
+ import { setJSExceptionHandler } from 'react-native-exception-handler' ;
2
4
3
5
const errorHandler = ( e , isFatal ) => {
4
6
if ( isFatal ) {
@@ -12,7 +14,7 @@ const errorHandler = (e, isFatal) => {
12
14
[ {
13
15
text : 'Restart' ,
14
16
onPress : ( ) => {
15
- console . log ( 'test' ) ;
17
+ RNRestart . Restart ( ) ;
16
18
}
17
19
} ]
18
20
) ;
@@ -21,4 +23,4 @@ const errorHandler = (e, isFatal) => {
21
23
}
22
24
} ;
23
25
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 = ( ) => { } ;
2
2
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 ) => {
8
4
const allowed = allowedInDevMode ? true : ! __DEV__ ;
9
5
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 ) ;
15
7
} 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 ' ) ;
17
9
}
18
10
} ;
11
+
12
+ export default {
13
+ setJSExceptionHandler
14
+ } ;
You can’t perform that action at this time.
0 commit comments