import React, {Component} from 'react';
import PropTypes from 'prop-types';
import Page500 from 'shared/components/500';

class ErrorBoundary extends Component {
  static propTypes = {
    children: PropTypes.node
  };

  constructor(props) {
    super(props);
    this.state = {hasError: false};
  }

  componentDidCatch(error) {
    this.setState({hasError: true});
    // eslint-disable-next-line no-console
    console.error(error);
  }

  render() {
    return this.state.hasError ? <Page500 /> : this.props.children;
  }
}

export default ErrorBoundary;
