import React from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; export default class ErrorBoundary extends React.PureComponent { static propTypes = { children: PropTypes.node, }; state = { hasError: false, componentStack: undefined, } componentDidCatch(error, info) { this.setState({ hasError: true, error, componentStack: info && info.componentStack, }); } setTextareaRef = c => { this.textarea = c; } handleCopy = e => { if (!this.textarea) return; this.textarea.select(); this.textarea.setSelectionRange(0, 99999); document.execCommand('copy'); } getErrorText = () => { const { error, componentStack } = this.state; return error + componentStack; } clearCookies = e => { localStorage.clear(); sessionStorage.clear(); } render() { const { hasError } = this.state; if (!hasError) { return this.props.children; } const errorText = this.getErrorText(); return (