api-gateway / client /src /components /error-boundary.tsx
recursiverall's picture
Deploy api-gateway with HF Space support
034e664 verified
Raw History Blame Contribute Delete
842 Bytes
import { Component, type ReactNode } from 'react'
import { Button } from '@/components/ui/button'
interface Props {
children: ReactNode
}
interface State {
hasError: boolean
}
export class ErrorBoundary extends Component<Props, State> {
state: State = { hasError: false }
static getDerivedStateFromError(): State {
return { hasError: true }
}
handleReload = () => {
this.setState({ hasError: false })
window.location.reload()
}
render() {
if (this.state.hasError) {
return (
<div className="flex flex-col items-center justify-center gap-4 py-20">
<p className="text-lg text-muted-foreground">Something went wrong</p>
<Button onClick={this.handleReload}>Reload</Button>
</div>
)
}
return this.props.children
}
}