-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathErrorHandler.jsx
More file actions
33 lines (29 loc) · 943 Bytes
/
ErrorHandler.jsx
File metadata and controls
33 lines (29 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react';
import { raiseException } from 'services/alerts';
import PageNotFound from './pages/PageNotFound';
// eslint-disable-next-line import/prefer-default-export
export class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError() {
// Update state so the next render will show the fallback UI.
// eslint-disable-next-line no-console
console.log(
'Something caused a crash during rendering, falling back to 404 url, please try again...'
);
return { hasError: true };
}
componentDidCatch(error, errorInfo) {
// log the error to our error reporting service
raiseException(error, 'Error Boundary', errorInfo);
}
render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return <PageNotFound />;
}
return this.props.children;
}
}