From 55495ebf4f366bcb3d1d00466353fc7c082710fc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 5 Jul 2021 18:08:04 -0500 Subject: [PATCH] ErrorBoundary: display error text, fixes #672 --- app/soapbox/components/error_boundary.js | 30 +++++++++++++++++++++-- app/styles/components/error-boundary.scss | 12 +++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/soapbox/components/error_boundary.js b/app/soapbox/components/error_boundary.js index 2cb6b514a..83b6b8e42 100644 --- a/app/soapbox/components/error_boundary.js +++ b/app/soapbox/components/error_boundary.js @@ -10,18 +10,35 @@ export default class ErrorBoundary extends React.PureComponent { state = { hasError: false, - stackTrace: undefined, componentStack: undefined, } componentDidCatch(error, info) { this.setState({ hasError: true, - stackTrace: error.stack, + 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(); @@ -34,6 +51,8 @@ export default class ErrorBoundary extends React.PureComponent { return this.props.children; } + const errorText = this.getErrorText(); + return (
@@ -43,6 +62,13 @@ export default class ErrorBoundary extends React.PureComponent {