Spaces:
Sleeping
Sleeping
Download src/components/ErrorBoundary.tsx from mozolla/pl-api-ogama: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/spaces/mozolla/pl-api-ogama/resolve/main/src/components/ErrorBoundary.tsx
- Command line
-
hf download hf://spaces/mozolla/pl-api-ogama/src/components/ErrorBoundary.tsx
-
curl -L -o ErrorBoundary.tsx https://huggingface.co/spaces/mozolla/pl-api-ogama/resolve/main/src/components/ErrorBoundary.tsx
1.78 kB
| import { Component, type ReactNode } from "react"; | |
| interface Props { | |
| children: ReactNode; | |
| fallback?: ReactNode; | |
| } | |
| interface State { | |
| hasError: boolean; | |
| error: Error | null; | |
| } | |
| export class ErrorBoundary extends Component<Props, State> { | |
| state: State = { hasError: false, error: null }; | |
| static getDerivedStateFromError(error: Error): State { | |
| return { hasError: true, error }; | |
| } | |
| render() { | |
| if (this.state.hasError) { | |
| if (this.props.fallback) return this.props.fallback; | |
| return ( | |
| <div className="flex min-h-screen items-center justify-center bg-slate-50 p-6"> | |
| <div className="max-w-md rounded-xl bg-white p-8 shadow-lg text-center"> | |
| <div className="mb-4 inline-flex h-16 w-16 items-center justify-center rounded-full bg-red-100"> | |
| <svg className="h-8 w-8 text-red-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}> | |
| <path strokeLinecap="round" strokeLinejoin="round" d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /> | |
| </svg> | |
| </div> | |
| <h2 className="text-lg font-semibold text-slate-800 mb-2">Something went wrong</h2> | |
| <p className="text-sm text-slate-500 mb-4"> | |
| {this.state.error?.message || "An unexpected error occurred."} | |
| </p> | |
| <button | |
| onClick={() => { this.setState({ hasError: false, error: null }); window.location.reload(); }} | |
| className="rounded-lg bg-violet-600 px-4 py-2 text-sm font-medium text-white hover:bg-violet-700 transition-colors" | |
| > | |
| Reload Page | |
| </button> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| return this.props.children; | |
| } | |
| } |