import React, { Component, ErrorInfo, ReactNode } from 'react'; import { Button } from './ui/button'; import { Card } from './ui/card'; import { AlertTriangle } from '@phosphor-icons/react'; import { captureError } from '../lib/sentry'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; } export class ErrorBoundary extends Component { public state: State = { hasError: false, error: null, errorInfo: null, }; public static getDerivedStateFromError(error: Error): State { return { hasError: true, error, errorInfo: null }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Uncaught error:', error, errorInfo); this.setState({ error, errorInfo, }); // Report to Sentry if (typeof captureError === 'function') { captureError(error, { extra: { errorInfo } }); } } private handleReset = () => { this.setState({ hasError: false, error: null, errorInfo: null }); window.location.reload(); }; private handleResetWithoutReload = () => { this.setState({ hasError: false, error: null, errorInfo: null }); }; public render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Something went wrong

An unexpected error occurred in the application

{this.state.error && (

{this.state.error.toString()}

{this.state.errorInfo && (
                    {this.state.errorInfo.componentStack}
                  
)}
)}

If this problem persists, please report it to the development team

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