Files
ETB/ETB-FrontEnd/node_modules/@mui/x-data-grid/modern/components/ErrorBoundary.js
Iliyan Angelov 306b20e24a Frontend start
2025-09-14 00:54:48 +03:00

35 lines
877 B
JavaScript

import * as React from 'react';
export class ErrorBoundary extends React.Component {
static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
return {
hasError: true,
error
};
}
componentDidCatch(error, errorInfo) {
if (this.props.api.current) {
this.logError(error); // Allows to trigger the Error event and all listener can run on Error
this.props.api.current.showError({
error,
errorInfo
});
}
}
logError(error, errorInfo) {
this.props.logger.error(`An unexpected error occurred. Error: ${error && error.message}. `, error, errorInfo);
}
render() {
if (this.props.hasError || this.state?.hasError) {
// You can render any custom fallback UI
return this.props.render(this.state);
}
return this.props.children;
}
}