Skip to content

Commit

Permalink
fix(rn): replace console.errors by alerts
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Nov 28, 2018
1 parent 760e3e6 commit a34455f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
1 change: 0 additions & 1 deletion client/react-native/common/components/App.js
Expand Up @@ -63,7 +63,6 @@ export default class App extends PureComponent {

render () {
const { loading, deepLink } = this.state

if (loading) {
return <Loader />
}
Expand Down
Expand Up @@ -142,6 +142,10 @@ export default class List extends PureComponent {
throw new Error('thrown exception')
}

jsConsoleError = () => {
console.error('console error')
}

render () {
const { navigation } = this.props
const { restartDaemon, panic } = this.state
Expand Down Expand Up @@ -200,6 +204,11 @@ export default class List extends PureComponent {
title='Throw JS exception'
onPress={this.throwJsException}
/>
<Menu.Item
icon='slash'
title='JS console error'
onPress={this.jsConsoleError}
/>
<Menu.Item
icon='list'
title='List events'
Expand Down
37 changes: 19 additions & 18 deletions client/react-native/common/helpers/crash-handler.js
Expand Up @@ -5,28 +5,29 @@ import {
} from 'react-native-exception-handler'
import RNRestart from 'react-native-restart'

const exceptionHandler = (error, isFatal) => {
Alert.alert(
'An unexpected error has occurred.',
`${isFatal ? 'Fatal: ' : ''}${
!error || typeof error === 'string' ? error : error.toString()
}`,
[
{
text: 'Restart',
onPress: () => RNRestart.Restart(),
},
!isFatal && { text: 'Cancel' },
],
{ cancelable: false }
)
}

// eslint-disable-next-line
if (__DEV__ == null || __DEV__ == false) {
console.error = console.warn
if (!__DEV__) {
console.error = error => exceptionHandler(error, false)
}

if (Platform.OS === 'ios' || Platform.OS === 'android') {
const exceptionHandler = (error, isFatal) => {
Alert.alert(
null,
`An unexpected error has occurred. Please restart to continue.
${typeof isFatal === 'undefined' || isFatal ? 'Fatal ' : ''} Error:
${typeof error === 'string' ? error : error.name + ' ' + error.message}
`,
[
{
text: 'Restart',
onPress: () => RNRestart.Restart(),
},
],
{ cancelable: false }
)
}
const allowInDevMode = false
const forceAppQuit = false
const executeDefaultHandler = false
Expand Down

0 comments on commit a34455f

Please sign in to comment.