Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3382794
D3811.id11757.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D3811.id11757.diff
View Options
diff --git a/web/error-boundary.css b/web/error-boundary.css
new file mode 100644
--- /dev/null
+++ b/web/error-boundary.css
@@ -0,0 +1,9 @@
+.container {
+ height: 100vh;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ color: var(--fg);
+ font-size: var(--m-font-16);
+}
diff --git a/web/error-boundary.react.js b/web/error-boundary.react.js
new file mode 100644
--- /dev/null
+++ b/web/error-boundary.react.js
@@ -0,0 +1,42 @@
+// @flow
+
+import * as React from 'react';
+
+import type { ErrorInfo, ErrorData } from 'lib/types/report-types';
+
+import css from './error-boundary.css';
+
+type Props = {
+ children: React.Node,
+};
+
+type State = {
+ errorData: $ReadOnlyArray<ErrorData>,
+ showError: boolean,
+};
+
+class ErrorBoundary extends React.PureComponent<Props, State> {
+ state: State = {
+ errorData: [],
+ showError: false,
+ };
+
+ componentDidCatch(error: Error, info: ErrorInfo) {
+ this.setState(prevState => ({
+ errorData: [...prevState.errorData, { error, info }],
+ }));
+ }
+
+ render(): React.Node {
+ if (this.state.errorData.length > 0) {
+ return (
+ <div className={css.container}>
+ <h3>Something has gone wrong, please reload the page</h3>
+ </div>
+ );
+ }
+ return this.props.children;
+ }
+}
+
+export default ErrorBoundary;
diff --git a/web/hot.js b/web/hot.js
--- a/web/hot.js
+++ b/web/hot.js
@@ -5,15 +5,18 @@
import { Router, Route } from 'react-router';
import App from './app.react';
+import ErrorBoundary from './error-boundary.react';
import history from './router-history';
import Socket from './socket.react';
const RootComponent = () => (
<React.Fragment>
- <Router history={history.getHistoryObject()}>
- <Route path="*" component={App} />
- </Router>
- <Socket />
+ <ErrorBoundary>
+ <Router history={history.getHistoryObject()}>
+ <Route path="*" component={App} />
+ </Router>
+ <Socket />
+ </ErrorBoundary>
</React.Fragment>
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 12:02 PM (21 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2596922
Default Alt Text
D3811.id11757.diff (2 KB)
Attached To
Mode
D3811: [web] [feat/chore] [ENG-813] add error boundary to the app
Attached
Detach File
Event Timeline
Log In to Comment