Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
at main 42 lines 1.0 kB view raw
1import logger from "@hey/helpers/logger"; 2import type { ErrorInfo, ReactNode } from "react"; 3import { Component } from "react"; 4import SiteError from "@/components/Shared/SiteError"; 5 6interface ErrorBoundaryProps { 7 children?: ReactNode; 8} 9 10interface ErrorBoundaryState { 11 hasError: boolean; 12 message: string; 13} 14 15class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { 16 public state: ErrorBoundaryState = { 17 hasError: false, 18 message: "" 19 }; 20 21 public static getDerivedStateFromError(error: Error): ErrorBoundaryState { 22 return { hasError: true, message: error.message }; 23 } 24 25 public componentDidCatch(error: Error, errorInfo: ErrorInfo) { 26 logger.error("Uncaught error:", error, errorInfo); 27 } 28 29 public render() { 30 if (this.state.hasError) { 31 return ( 32 <div className="flex h-screen items-center justify-center"> 33 <SiteError message={this.state.message} /> 34 </div> 35 ); 36 } 37 38 return this.props.children; 39 } 40} 41 42export default ErrorBoundary;