sdlc-hub/web/src/shell/ErrorBoundary.tsx
2026-10-14 20:14:27 +04:00

21 lines
1010 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Component, type ErrorInfo, type ReactNode } from "react";
interface State { error: Error | null }
// неожиданная ошибка отрисовки страницы: сообщение и перезагрузка вместо пустого экрана; панель разделов остаётся
export class ErrorBoundary extends Component<{ children: ReactNode }, State> {
state: State = { error: null };
static getDerivedStateFromError(error: Error): State { return { error }; }
componentDidCatch(error: Error, info: ErrorInfo) { console.error("ошибка страницы", error, info.componentStack); }
render() {
if (!this.state.error) return this.props.children;
return (
<div className="crash" role="alert">
<h2>Страница сломалась</h2>
<p>{this.state.error.message}</p>
<button className="btn" type="button" onClick={() => window.location.reload()}>Перезагрузить</button>
</div>
);
}
}