codekingpro/portable-devtools
114k
1/////////////////////////////////////////////////////////////2//3// pgAdmin 4 - PostgreSQL Tools4//5// Copyright (C) 2013 - 2024, The pgAdmin Development Team6// This software is released under the PostgreSQL Licence7//8//////////////////////////////////////////////////////////////9 10/* https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html */11import React from 'react';12import CustomPropTypes from '../custom_prop_types';13 14export default class ErrorBoundary extends React.Component {15 constructor(props) {16 super(props);17 this.state = { hasError: false };18 }19 20 componentDidCatch(error, info) {21 // Display fallback UI22 this.setState({ hasError: true });23 // You can also log the error to an error reporting service24 console.error(error, info);25 }26 27 render() {28 if (this.state.hasError) {29 // You can render any custom fallback UI30 return <h2>Something went wrong.</h2>;31 }32 return this.props.children;33 }34}35 36ErrorBoundary.propTypes = {37 children: CustomPropTypes.children,38};39 