mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
Add Error Boundary for Pages
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
//@flow
|
||||||
|
|
||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
|
||||||
|
class PageErrorBoundary extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { hasError: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This lifecycle is invoked after an error has been thrown by a descendant component.
|
||||||
|
* It receives the error that was thrown as a parameter and should return a value to update state.
|
||||||
|
* @param error
|
||||||
|
* @returns {{hasError: boolean}}
|
||||||
|
*/
|
||||||
|
static getDerivedStateFromError(error) {
|
||||||
|
// Update state so the next render will show the fallback UI.
|
||||||
|
return { hasError: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (this.state.hasError) {
|
||||||
|
return <h1>Something went wrong.</h1>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PageErrorBoundary;
|
||||||
@@ -7,6 +7,7 @@ import Subtitle from "./Subtitle";
|
|||||||
import injectSheet from "react-jss";
|
import injectSheet from "react-jss";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import PageActions from "./PageActions";
|
import PageActions from "./PageActions";
|
||||||
|
import PageErrorBoundary from "../errorboundary/PageErrorBoundary";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title?: string,
|
title?: string,
|
||||||
@@ -31,13 +32,15 @@ class Page extends React.Component<Props> {
|
|||||||
render() {
|
render() {
|
||||||
const { error } = this.props;
|
const { error } = this.props;
|
||||||
return (
|
return (
|
||||||
<section className="section">
|
<PageErrorBoundary>
|
||||||
<div className="container">
|
<section className="section">
|
||||||
{this.renderPageHeader()}
|
<div className="container">
|
||||||
<ErrorNotification error={error} />
|
{this.renderPageHeader()}
|
||||||
{this.renderContent()}
|
<ErrorNotification error={error} />
|
||||||
</div>
|
{this.renderContent()}
|
||||||
</section>
|
</div>
|
||||||
|
</section>
|
||||||
|
</PageErrorBoundary>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user