This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an error boundary around the top level as well
- Loading branch information
Dom Harrington
committed
Aug 30, 2018
1 parent
85ca38d
commit f6a00cc
Showing
4 changed files
with
62 additions
and
3 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,42 @@ | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
|
||
class ErrorBoundary extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { error: false }; | ||
} | ||
|
||
componentDidCatch(error, info) { | ||
this.setState({ error, info }); | ||
// TODO add bugsnag here? | ||
// You can also log the error to an error reporting service | ||
// logErrorToMyService(error, info); | ||
} | ||
|
||
render() { | ||
if (this.state.error) { | ||
return ( | ||
<div style={{ paddingLeft: '2%' }}> | ||
<h3> | ||
There was an error rendering the API Explorer. If you are the owner of this project | ||
please contact{' '} | ||
<a href="mailto:support@readme.io?subject=API Explorer Error">support@readme.io</a> with | ||
the following error: | ||
</h3> | ||
<pre> | ||
{this.state.error && this.state.error.toString()} | ||
{this.state.info.componentStack} | ||
</pre> | ||
</div> | ||
); | ||
} | ||
return this.props.children; | ||
} | ||
} | ||
|
||
ErrorBoundary.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
module.exports = 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