telegram-invite-automation/src/renderer/components/ErrorBoundary.jsx
2026-02-01 14:37:52 +04:00

41 lines
1.0 KiB
JavaScript

import React from "react";
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false, message: "" };
}
static getDerivedStateFromError(error) {
return { hasError: true, message: error?.message || "Неизвестная ошибка." };
}
componentDidCatch(error, info) {
// eslint-disable-next-line no-console
console.error("UI error boundary:", error, info);
}
handleReload = () => {
window.location.reload();
};
render() {
if (this.state.hasError) {
return (
<div className="error-boundary">
<div className="error-boundary-card">
<h3>Интерфейс временно недоступен</h3>
<p>{this.state.message}</p>
<button className="primary" onClick={this.handleReload}>
Перезагрузить
</button>
</div>
</div>
);
}
return this.props.children;
}
}
export default ErrorBoundary;