lgklsv / graphiql

GraphQL Playground

Home Page:https://graphiql-ide.web.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error boundary

lgklsv opened this issue · comments

commented

research needed...

https://learn.react-js.dev/advanced-concepts/error-boundaries

https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary

export class ErrorBoundary extends Component {
  static propTypes = {
    children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
    message: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
  };

  static defaultProps = {
    children: null,
    message: null,
  };

  state = {
    hasError: false,
  };

  componentDidCatch(error, info) {
    this.setState({
      hasError: true,
      error,
      info,
    });
    logger('error', error, info);
  }

  render() {
    const { hasError, error, info } = this.state;
    const ErrorMessage = this.props.message;

    if (!hasError) return this.props.children;
    if (!ErrorMessage) return null;

    return <ErrorMessage error={error} info={info} />;
  }
}