-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add generic error boundary, apply to preview iframe
- Loading branch information
Showing
4 changed files
with
55 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.nc-errorBoundary { | ||
padding: 0 20px; | ||
} | ||
|
||
.nc-errorBoundary-heading, | ||
.nc-errorBoundary-link { | ||
color: var(--errorColor); | ||
} |
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,35 @@ | ||
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> | ||
); | ||
}; | ||
|
||
export default class ErrorBoundary extends React.Component { | ||
static propTypes = { | ||
render: PropTypes.element, | ||
}; | ||
|
||
state = { | ||
hasError: false, | ||
}; | ||
|
||
componentDidCatch(error) { | ||
console.error(error); | ||
this.setState({ hasError: true }); | ||
} | ||
|
||
render() { | ||
const errorComponent = this.props.errorComponent || <ErrorComponent/>; | ||
return this.state.hasError ? errorComponent : this.props.children; | ||
} | ||
} |
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