2018-11-28 06:01:40 -08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
2018-11-28 06:35:44 -08:00
|
|
|
import { preferencesLink } from 'flavours/glitch/util/backend_links';
|
2018-11-28 06:01:40 -08:00
|
|
|
|
|
|
|
export default class ErrorBoundary extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
hasError: false,
|
|
|
|
stackTrace: undefined,
|
|
|
|
componentStack: undefined,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidCatch(error, info) {
|
|
|
|
this.setState({
|
|
|
|
hasError: true,
|
|
|
|
stackTrace: error.stack,
|
|
|
|
componentStack: info && info.componentStack,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleReload(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { hasError, stackTrace, componentStack } = this.state;
|
|
|
|
|
|
|
|
if (!hasError) return this.props.children;
|
|
|
|
|
|
|
|
let debugInfo = '';
|
|
|
|
if (stackTrace) {
|
|
|
|
debugInfo += 'Stack trace\n-----------\n\n```\n' + stackTrace.toString() + '\n```';
|
|
|
|
}
|
|
|
|
if (componentStack) {
|
|
|
|
if (debugInfo) {
|
|
|
|
debugInfo += '\n\n\n';
|
|
|
|
}
|
|
|
|
debugInfo += 'React component stack\n---------------------\n\n```\n' + componentStack.toString() + '\n```';
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div tabIndex='-1'>
|
|
|
|
<div className='error-boundary'>
|
|
|
|
<h1><FormattedMessage id='web_app_crash.title' defaultMessage="We're sorry, but something went wrong with the Mastodon app." /></h1>
|
|
|
|
<p>
|
|
|
|
<FormattedMessage id='web_app_crash.content' defaultMessage='You could try any of the following:' />
|
2019-07-01 04:38:00 -07:00
|
|
|
</p>
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<FormattedMessage
|
|
|
|
id='web_app_crash.report_issue'
|
|
|
|
defaultMessage='Report a bug in the {issuetracker}'
|
2019-10-24 13:44:42 -07:00
|
|
|
values={{ issuetracker: <a href='https://github.com/glitch-soc/mastodon/issues' rel='noopener noreferrer' target='_blank'><FormattedMessage id='web_app_crash.issue_tracker' defaultMessage='issue tracker' /></a> }}
|
2019-07-01 04:38:00 -07:00
|
|
|
/>
|
|
|
|
{ debugInfo !== '' && (
|
|
|
|
<details>
|
|
|
|
<summary><FormattedMessage id='web_app_crash.debug_info' defaultMessage='Debug information' /></summary>
|
|
|
|
<textarea
|
|
|
|
className='web_app_crash-stacktrace'
|
|
|
|
value={debugInfo}
|
|
|
|
rows='10'
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
</details>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<FormattedMessage
|
|
|
|
id='web_app_crash.reload_page'
|
|
|
|
defaultMessage='{reload} the current page'
|
|
|
|
values={{ reload: <a href='#' onClick={this.handleReload}><FormattedMessage id='web_app_crash.reload' defaultMessage='Reload' /></a> }}
|
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
{ preferencesLink !== undefined && (
|
2018-11-28 06:01:40 -08:00
|
|
|
<li>
|
|
|
|
<FormattedMessage
|
2019-07-01 04:38:00 -07:00
|
|
|
id='web_app_crash.change_your_settings'
|
|
|
|
defaultMessage='Change your {settings}'
|
|
|
|
values={{ settings: <a href={preferencesLink}><FormattedMessage id='web_app_crash.settings' defaultMessage='settings' /></a> }}
|
2018-11-28 06:01:40 -08:00
|
|
|
/>
|
|
|
|
</li>
|
2019-07-01 04:38:00 -07:00
|
|
|
)}
|
|
|
|
</ul>
|
2018-11-28 06:01:40 -08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|