-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
makes crashes graceful
- Loading branch information
Showing
7 changed files
with
104 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { Component, ErrorInfo, ReactNode } from 'react'; | ||
import ErrorInfoComponent from './ErrorInfo'; | ||
|
||
type Props = { | ||
children: ReactNode; | ||
}; | ||
type State = { | ||
hasError: boolean; | ||
}; | ||
|
||
class ErrorBoundary extends Component<Props, State> { | ||
state: State = { | ||
hasError: false, | ||
}; | ||
|
||
static getDerivedStateFromError(error: Error): State { | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch(error: Error, errorInfo: ErrorInfo) { | ||
console.error('Uncaught error:', error, errorInfo); | ||
} | ||
|
||
resetError() { | ||
this.setState({ hasError: false }); | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) | ||
return ( | ||
<ErrorInfoComponent | ||
message='Something weird happened on your browser.' | ||
misc={{ | ||
subtext: 'Check console for more information.', | ||
buttonClickHandler: this.resetError.bind(this), | ||
buttonText: 'Reload Page', | ||
}} | ||
/> | ||
); | ||
|
||
return this.props.children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import ErrorInfo from '../components/error/ErrorInfo'; | ||
|
||
const Error404 = () => { | ||
return <ErrorInfo />; | ||
return <ErrorInfo message='Not found, sorry.' statusCode={404} />; | ||
}; | ||
|
||
export default Error404; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import ErrorInfo from '../components/error/ErrorInfo'; | ||
|
||
const Error500 = () => { | ||
return <ErrorInfo message="server messed up, sorry." statusCode={500} />; | ||
return <ErrorInfo message='Server messed up, sorry.' statusCode={500} />; | ||
}; | ||
export default Error500; |
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