lossless-cut/src/renderer/src/ErrorBoundary.jsx

38 wiersze
1.1 KiB
React
Czysty Zwykły widok Historia

2024-02-20 14:51:33 +00:00
import { Component } from 'react';
2021-03-29 15:11:08 +00:00
import { Trans } from 'react-i18next';
2020-04-10 14:04:19 +00:00
import { openSendReportDialog } from './reporting';
class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { error: undefined };
}
static getDerivedStateFromError(error) {
return { error };
}
componentDidCatch(error, errorInfo) {
console.error('componentDidCatch', error, errorInfo);
}
render() {
const { error } = this.state;
if (error) {
return (
<div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
2021-03-29 15:11:08 +00:00
<h1><Trans>Something went wrong</Trans></h1>
2020-04-10 14:04:19 +00:00
<div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-all' }}>{error.message}</div>
2021-03-29 15:11:08 +00:00
<p><button type="button" onClick={() => openSendReportDialog(error)} style={{ padding: 10, fontSize: 20 }}><Trans>Report error</Trans></button></p>
2020-04-10 14:04:19 +00:00
</div>
);
}
2021-03-30 15:01:25 +00:00
// eslint-disable-next-line react/destructuring-assignment
2020-04-10 14:04:19 +00:00
return this.props.children;
}
}
export default ErrorBoundary;