Spaces:
Runtime error
Runtime error
File size: 1,523 Bytes
ef865f2 | 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 41 42 43 44 | import React from 'react';
import { AlertTriangle, RefreshCw } from 'lucide-react';
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error) {
return { hasError: true, error };
}
componentDidCatch(error, info) {
console.error('[ErrorBoundary]', error, info);
}
render() {
if (this.state.hasError) {
return (
<div className="flex-1 flex flex-col items-center justify-center p-12 text-center bg-[var(--bg-primary)]">
<div className="w-16 h-16 bg-red-500/10 border border-red-500/20 rounded-2xl flex items-center justify-center mb-6">
<AlertTriangle size={32} className="text-red-500" />
</div>
<h2 className="text-xl font-semibold text-[var(--text-primary)] mb-2">Something went wrong</h2>
<p className="text-sm text-[var(--text-secondary)] mb-6 max-w-sm font-mono break-words">
{this.state.error?.message || 'An unexpected error occurred.'}
</p>
<button
onClick={() => this.setState({ hasError: false, error: null })}
className="flex items-center space-x-2 px-4 py-2 bg-[var(--accent-gradient)] text-white text-sm font-semibold rounded-lg shadow-lg"
>
<RefreshCw size={14} />
<span>Try Again</span>
</button>
</div>
);
}
return this.props.children;
}
}
export default ErrorBoundary;
|