-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
130 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { Component } from 'react' | ||
import { View, Text, StyleSheet } from 'react-native' | ||
|
||
import { vars } from '../../styles.js' | ||
import Wrapper from './Wrapper.jsx' | ||
import Header from '../reusable/Header.jsx' | ||
import LinkButton from '../reusable/LinkButton.jsx' | ||
|
||
let styles | ||
|
||
export class ErrorBoundary extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { hasError: false } | ||
} | ||
|
||
static getDerivedStateFromError() { | ||
return { hasError: true } | ||
} | ||
|
||
componentDidCatch(error, errorInfo) { | ||
// TODO: Log error to an error reporting service | ||
console.error(error, errorInfo) | ||
} | ||
|
||
render() { | ||
const { hasError } = this.state | ||
if (hasError) { | ||
// You can render any custom fallback UI | ||
return ( | ||
<Wrapper> | ||
<View style={styles.wrapper}> | ||
<Header title="Error!" hideClose /> | ||
<View style={styles.error}> | ||
<Text style={styles.errorMessage}> | ||
There was an unexpected error. You can either try reload this | ||
page, or return home. | ||
</Text> | ||
<LinkButton | ||
href={window.location.toString()} | ||
target="_self" | ||
label="Reload Page" | ||
/> | ||
<LinkButton | ||
color="secondary" | ||
href="/" | ||
label="Return Home" | ||
target="_self" | ||
/> | ||
</View> | ||
</View> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
const { children } = this.props | ||
return children | ||
} | ||
} | ||
|
||
const { padding, defaultFontSize, fontFamily } = vars | ||
styles = StyleSheet.create({ | ||
wrapper: { | ||
flex: 1, | ||
}, | ||
error: { | ||
padding, | ||
}, | ||
errorMessage: { | ||
fontSize: defaultFontSize, | ||
fontFamily, | ||
marginBottom: padding, | ||
}, | ||
}) |