Spaces:
Sleeping
Sleeping
Download src/components/ui/ScreenErrorBoundary.tsx from Samfredoly/jor: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/Samfredoly/jor/resolve/main/src/components/ui/ScreenErrorBoundary.tsx
- Command line
-
hf download hf://spaces/Samfredoly/jor/src/components/ui/ScreenErrorBoundary.tsx
-
curl -L -o ScreenErrorBoundary.tsx https://huggingface.co/spaces/Samfredoly/jor/resolve/main/src/components/ui/ScreenErrorBoundary.tsx
1.14 kB
| import { Component, type ErrorInfo, type ReactNode } from 'react' | |
| type ScreenErrorBoundaryProps = { | |
| children: ReactNode | |
| } | |
| type ScreenErrorBoundaryState = { | |
| error: Error | null | |
| } | |
| export class ScreenErrorBoundary extends Component<ScreenErrorBoundaryProps, ScreenErrorBoundaryState> { | |
| state: ScreenErrorBoundaryState = { error: null } | |
| static getDerivedStateFromError(error: Error): ScreenErrorBoundaryState { | |
| return { error } | |
| } | |
| componentDidCatch(error: Error, errorInfo: ErrorInfo) { | |
| console.error('Screen rendering failed.', error, errorInfo.componentStack) | |
| } | |
| private retry = () => { | |
| this.setState({ error: null }) | |
| } | |
| render() { | |
| if (this.state.error) { | |
| return ( | |
| <section className="panel" role="alert"> | |
| <h2 className="section-title">This screen could not be displayed</h2> | |
| <p className="muted">{this.state.error.message || 'An unexpected error occurred.'}</p> | |
| <button className="button button-primary" onClick={this.retry}>Try again</button> | |
| </section> | |
| ) | |
| } | |
| return this.props.children | |
| } | |
| } | |