ErrorBoundary: display error text, fixes #672

actually-fix-tabs-bar
Alex Gleason 2021-07-05 18:08:04 -05:00
rodzic 669b12a648
commit 55495ebf4f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 38 dodań i 4 usunięć

Wyświetl plik

@ -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 (
<div className='error-boundary'>
<div>
@ -43,6 +62,13 @@ export default class ErrorBoundary extends React.PureComponent {
<i className='fa fa-reply' aria-hidden='true' />&nbsp;
<FormattedMessage id='alert.unexpected.return_home' defaultMessage='Return Home' />
</a>
{errorText && <textarea
ref={this.setTextareaRef}
className='error-boundary__component-stack'
value={errorText}
onClick={this.handleCopy}
readOnly
/>}
<p className='help-text'>
<FormattedMessage
id='alert.unexpected.help_text'

Wyświetl plik

@ -9,7 +9,7 @@
display: block;
text-align: center;
font-size: 70px;
margin-bottom: 20px;
margin: 20px 0;
opacity: 0.5;
}
@ -38,8 +38,16 @@
font-style: italic;
font-size: 14px;
padding: 20px 10px 0;
margin-top: 70px;
margin-top: 20px;
opacity: 0.7;
border-top: 1px solid;
}
&__component-stack {
width: 100%;
height: 200px;
text-align: left;
margin: 20px 0;
padding: 10px;
}
}