2021-12-21 15:21:59 +00:00
|
|
|
import React, { Component } from 'react';
|
2022-09-14 08:04:49 +00:00
|
|
|
import { withTranslation } from 'react-i18next';
|
2023-12-12 12:15:54 +00:00
|
|
|
import * as Sentry from '@sentry/react';
|
2021-12-21 15:21:59 +00:00
|
|
|
|
|
|
|
|
class ErrorBoundary extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = { hasError: false };
|
|
|
|
|
}
|
2021-12-30 11:57:02 +00:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2021-12-21 15:21:59 +00:00
|
|
|
static getDerivedStateFromError(error) {
|
|
|
|
|
// Update state so the next render will show the fallback UI.
|
|
|
|
|
return { hasError: true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidCatch(error, errorInfo) {
|
|
|
|
|
// You can also log the error to an error reporting service
|
|
|
|
|
console.log(error, errorInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2023-12-12 12:15:54 +00:00
|
|
|
return (
|
|
|
|
|
<Sentry.ErrorBoundary fallback={<h2>{this.props.t('errorBoundary', 'Something went wrong.')}</h2>}>
|
|
|
|
|
{this.props.children}
|
|
|
|
|
</Sentry.ErrorBoundary>
|
|
|
|
|
);
|
2021-12-21 15:21:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-14 08:04:49 +00:00
|
|
|
export default withTranslation()(ErrorBoundary);
|