-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorBoundary.js
46 lines (40 loc) · 1.27 KB
/
ErrorBoundary.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from "react";
import { captureException } from "@sentry/react";
import { Alert, AlertTitle } from "@mui/material";
export class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
deleteLocalStorage = () => {
localStorage.removeItem("obce");
localStorage.removeItem("municipalities");
window.location.reload();
};
static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
return { hasError: true };
}
componentDidCatch(error, errorInfo) {
// You can also log the error to an error reporting service
console.log("error: ", error, errorInfo);
window.gtag("event", "exception", {
error: error,
stack: errorInfo.componentStack,
});
captureException(error, { extra: errorInfo });
}
render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return (
<Alert severity="error">
<AlertTitle>Něco se pokazilo</AlertTitle>
Zkuste to prosím znovu později. V případě přetrvávajících potíží mě
prosím kontaktujte na e-mailu covid-obce@petrhovorka.com.
</Alert>
);
}
return this.props.children;
}
}