Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | import React, { Component, ErrorInfo } from "react";
import serverError from "@/assets/server-error.svg";
interface ErrorBoundaryState {
hasError: boolean;
errorMessage: string;
}
class ErrorBoundry extends Component<React.PropsWithChildren, ErrorBoundaryState> {
constructor(props: React.PropsWithChildren) {
super(props);
this.state = {
hasError: false,
errorMessage: "",
};
}
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
return { hasError: true, errorMessage: error.message };
}
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
console.error("Error occurred:", error, errorInfo);
}
render() {
if (this.state.hasError) {
return (
<div className="flex items-center flex-col gap-4 my-10">
<img className="w-[200px] " src={serverError} />
<p className="text-xl">Something went wrong: {this.state.errorMessage}</p>
</div>
);
}
return this.props.children;
}
}
export default ErrorBoundry;
|