github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/ui/dashboard/src/components/ErrorBoundary/index.tsx (about) 1 import ErrorModal from "../Modal/ErrorModal"; 2 import { Component, ReactNode } from "react"; 3 4 type ErrorBoundaryProps = { 5 children: ReactNode; 6 }; 7 8 class ErrorBoundary extends Component<ErrorBoundaryProps> { 9 state = { 10 error: null, 11 errorInfo: null, 12 modalOpen: false, 13 }; 14 15 componentDidCatch(error, errorInfo) { 16 // Catch errors in any components below and re-render with error message 17 this.setState({ 18 error: error, 19 errorInfo: errorInfo, 20 modalOpen: true, 21 }); 22 } 23 24 render() { 25 if (this.state.error && this.state.modalOpen) { 26 return ( 27 <ErrorModal 28 error={this.state.error} 29 title="Sorry, but something went wrong" 30 /> 31 ); 32 } 33 return this.props.children; 34 } 35 } 36 37 export default ErrorBoundary;