From 2acf5f8966a40c1c9a97680c8dc263ee3f1ad3d1 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 2 Jul 2025 00:45:49 +0000 Subject: (대표님/최겸) 20250702 변경사항 업데이트 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/error-boundary.tsx | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 components/error-boundary.tsx (limited to 'components/error-boundary.tsx') diff --git a/components/error-boundary.tsx b/components/error-boundary.tsx new file mode 100644 index 00000000..41334eb7 --- /dev/null +++ b/components/error-boundary.tsx @@ -0,0 +1,45 @@ +"use client"; + +import * as React from "react"; + +interface ErrorBoundaryProps { + children: React.ReactNode; + fallback: React.ComponentType<{ error: Error; reset: () => void }>; +} + +interface ErrorBoundaryState { + hasError: boolean; + error: Error | null; +} + +export class ErrorBoundary extends React.Component< + ErrorBoundaryProps, + ErrorBoundaryState +> { + constructor(props: ErrorBoundaryProps) { + super(props); + this.state = { hasError: false, error: null }; + } + + static getDerivedStateFromError(error: Error): ErrorBoundaryState { + return { hasError: true, error }; + } + + componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { + console.error("Dashboard error boundary caught an error:", error, errorInfo); + } + + render() { + if (this.state.hasError && this.state.error) { + const Fallback = this.props.fallback; + return ( + this.setState({ hasError: false, error: null })} + /> + ); + } + + return this.props.children; + } +} \ No newline at end of file -- cgit v1.2.3