Merge branch 'error-text' into 'develop'
ErrorBoundary: display error text, fixes #672 Closes #672 See merge request soapbox-pub/soapbox-fe!581
This commit is contained in:
commit
d7247c902b
|
@ -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' />
|
||||
<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'
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue