闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
734 B

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import illustration from '../../images/elephant_ui_disappointed.svg';
  4. export default class ErrorBoundary extends React.PureComponent {
  5. static propTypes = {
  6. children: PropTypes.node,
  7. };
  8. state = {
  9. hasError: false,
  10. stackTrace: undefined,
  11. componentStack: undefined,
  12. }
  13. componentDidCatch(error, info) {
  14. this.setState({
  15. hasError: true,
  16. stackTrace: error.stack,
  17. componentStack: info && info.componentStack,
  18. });
  19. }
  20. render() {
  21. const { hasError } = this.state;
  22. if (!hasError) {
  23. return this.props.children;
  24. }
  25. return (
  26. <div>
  27. <img src={illustration} alt='' />
  28. </div>
  29. );
  30. }
  31. }