-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
print error messages in error boundary component
- Loading branch information
Showing
1 changed file
with
19 additions
and
18 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 |
---|---|---|
@@ -1,35 +1,36 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
const ErrorComponent = () => { | ||
const issueUrl = "https://github.com/netlify/netlify-cms/issues/new"; | ||
return ( | ||
<div className="nc-errorBoundary"> | ||
<h1 className="nc-errorBoundary-heading">Sorry!</h1> | ||
<p> | ||
<span>There's been an error - please </span> | ||
<a href={issueUrl} target="_blank" className="nc-errorBoundary-link">report it</a>! | ||
</p> | ||
</div> | ||
); | ||
const DefaultErrorComponent = () => { | ||
}; | ||
|
||
export class ErrorBoundary extends React.Component { | ||
static propTypes = { | ||
render: PropTypes.element, | ||
}; | ||
const ISSUE_URL = "https://github.com/netlify/netlify-cms/issues/new"; | ||
|
||
export class ErrorBoundary extends React.Component { | ||
state = { | ||
hasError: false, | ||
errorMessage: '', | ||
}; | ||
|
||
componentDidCatch(error) { | ||
console.error(error); | ||
this.setState({ hasError: true }); | ||
this.setState({ hasError: true, errorMessage: error.toString() }); | ||
} | ||
|
||
render() { | ||
const errorComponent = this.props.errorComponent || <ErrorComponent/>; | ||
return this.state.hasError ? errorComponent : this.props.children; | ||
const { hasError, errorMessage } = this.state; | ||
if (!hasError) { | ||
return this.props.children; | ||
} | ||
return ( | ||
<div className="nc-errorBoundary"> | ||
<h1 className="nc-errorBoundary-heading">Sorry!</h1> | ||
<p> | ||
<span>There's been an error - please </span> | ||
<a href={ISSUE_URL} target="_blank" className="nc-errorBoundary-link">report it</a>! | ||
</p> | ||
<p>{errorMessage}</p> | ||
</div> | ||
); | ||
} | ||
} |