diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index 0c93501..2368817 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -3,6 +3,7 @@ import { Inter, Noto_Sans_KR } from 'next/font/google'; import './globals.css'; import { ThemeProvider } from '@/components/providers/theme-provider'; import { Toaster } from '@/components/ui/sonner'; +import { ErrorBoundary } from '@/components/error-boundary'; const inter = Inter({ subsets: ['latin'], @@ -34,7 +35,9 @@ export default function RootLayout({ enableSystem disableTransitionOnChange > - {children} + + {children} + diff --git a/frontend/src/components/error-boundary.tsx b/frontend/src/components/error-boundary.tsx new file mode 100644 index 0000000..007da7a --- /dev/null +++ b/frontend/src/components/error-boundary.tsx @@ -0,0 +1,73 @@ +'use client'; + +import React from 'react'; +import { Button } from '@/components/ui/button'; + +interface ErrorBoundaryProps { + children: React.ReactNode; +} + +interface ErrorBoundaryState { + hasError: boolean; +} + +export class ErrorBoundary extends React.Component { + constructor(props: ErrorBoundaryProps) { + super(props); + this.state = { hasError: false }; + } + + static getDerivedStateFromError(): ErrorBoundaryState { + return { hasError: true }; + } + + componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { + console.error('ErrorBoundary caught an error:', error, errorInfo); + } + + handleRetry = () => { + this.setState({ hasError: false }); + }; + + render() { + if (this.state.hasError) { + return ( +
+
+
+ + + +
+

+ 문제가 발생했습니다 +

+

+ 페이지를 새로고침 해주세요. +

+
+ + +
+
+
+ ); + } + + return this.props.children; + } +}