Tesseract / utils /app_utils /frontend /src /components /ErrorBoundary.tsx
yansari's picture
feat: intro page, undo/redo, transition fix, naming and stats polish
e0e4431
Raw
History Blame Contribute Delete
1.13 kB
import { Component, type ReactNode, type ErrorInfo } from 'react';
interface Props {
children: ReactNode;
}
interface State {
hasError: boolean;
message: string;
}
/** Catches any render/effect error so the app degrades to a recoverable
* message instead of a blank white screen. */
export default class ErrorBoundary extends Component<Props, State> {
state: State = { hasError: false, message: '' };
static getDerivedStateFromError(error: Error): State {
return { hasError: true, message: error.message };
}
componentDidCatch(error: Error, info: ErrorInfo) {
console.error('Caught by ErrorBoundary:', error, info);
}
render() {
if (this.state.hasError) {
return (
<div className="error-container">
<div className="error-message">
Something went wrong while updating the graph.
{this.state.message ? ` (${this.state.message})` : ''}
</div>
<button className="btn btn-primary" onClick={() => window.location.reload()}>
Reload
</button>
</div>
);
}
return this.props.children;
}
}