-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorboundary.jsx
52 lines (45 loc) · 1.36 KB
/
Errorboundary.jsx
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
47
48
49
50
51
52
import { Component } from "react";
class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { hasError: false, error: "", errorInfo: "" };
}
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
// logErrorToMyService(error, errorInfo);
console.log("ERROR", error, errorInfo);
this.setState({ error, errorInfo });
}
render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return (
<div>
<h2>Something went wrong</h2>
<p>
Try contacting developer{" "}
<a
href="https://github.com/shubhamV123/outline"
target="_blank"
rel="noopener noreferrer"
>
here
</a>
</p>
<details style={{ wordBreak: "break-word" }}>
{this.state.error && this.state.error.toString()}
<br />
{this.state.errorInfo.componentStack}
</details>
</div>
);
}
return this.props.children;
}
}
export default ErrorBoundary;