Spaces:
Runtime error
Runtime error
Download frontend-react/src/components/ErrorBoundary.jsx from Amitkasar/ai-api-testing: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/spaces/Amitkasar/ai-api-testing/resolve/main/frontend-react/src/components/ErrorBoundary.jsx
- Command line
-
hf download hf://spaces/Amitkasar/ai-api-testing/frontend-react/src/components/ErrorBoundary.jsx
-
curl -L -o ErrorBoundary.jsx https://huggingface.co/spaces/Amitkasar/ai-api-testing/resolve/main/frontend-react/src/components/ErrorBoundary.jsx
1.52 kB
| 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; | |