Skip to content

Commit

Permalink
print error messages in error boundary component
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Jun 5, 2018
1 parent 97bc711 commit 7e05ec3
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/components/UI/ErrorBoundary/ErrorBoundary.js
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>
);
}
}

0 comments on commit 7e05ec3

Please sign in to comment.