Add Error Boundary and Crash message

Added all the strings to general l10n as error boundary/crash message applies to all pages.
This commit is contained in:
chrisgarrity 2018-03-12 13:53:38 -04:00 committed by Ray Schamp
parent 37437636ff
commit 53ca763646
6 changed files with 116 additions and 15 deletions

View file

@ -0,0 +1,38 @@
const classNames = require('classnames');
const PropTypes = require('prop-types');
const React = require('react');
const FormattedMessage = require('react-intl').FormattedMessage;
const Button = require('../forms/button.jsx');
require('./crashmessage.scss');
const CrashMessage = props => (
<div className={classNames(['crash-container', props.className])}>
<img
className=""
src="/images/unhandled.png"
/>
<div className="crash-message">
<h2>
<FormattedMessage id="general.error" />
</h2>
<p>
<FormattedMessage id="general.unhandledError" />
</p>
<Button
className=""
onClick={props.onBack}
>
<FormattedMessage id="general.back" />
</Button>
</div>
</div>
);
CrashMessage.propTypes = {
className: PropTypes.string,
onBack: PropTypes.func
};
module.exports = CrashMessage;

View file

@ -0,0 +1,22 @@
.crash-container {
@import "../../colors";
@import "../../frameless";
margin: 3rem auto;
border: 1px solid $ui-border;
border-radius: 10px;
background-color: $background-color;
width: 60%;
overflow: hidden;
text-align: center;
img {
width: 100%;
}
.crash-message {
margin: 2rem;
}
}

View file

@ -0,0 +1,36 @@
const PropTypes = require('prop-types');
const React = require('react');
const CrashMessageComponent = require('../crashmessage/crashmessage.jsx');
import log from '../../lib/log.js';
class ErrorBoundary extends React.Component {
constructor (props) {
super(props);
this.state = {
hasError: false
};
}
componentDidCatch (error, info) {
// Display fallback UI
this.setState({hasError: true});
log.error(`Unhandled Error: ${error}, info: ${info}`);
}
handleBack () {
window.history.back();
}
render () {
if (this.state.hasError) {
return <CrashMessageComponent onBack={this.handleBack} />;
}
return this.props.children;
}
}
ErrorBoundary.propTypes = {
children: PropTypes.node
};
module.exports = ErrorBoundary;

View file

@ -4,24 +4,27 @@ const React = require('react');
const Navigation = require('../../navigation/www/navigation.jsx');
const Footer = require('../../footer/www/footer.jsx');
const ErrorBoundary = require('../../errorboundary/errorboundary.jsx');
const Page = props => (
<div className="page">
<div
className={classNames({
staging: process.env.SCRATCH_ENV === 'staging'
})}
id="navigation"
>
<Navigation />
<ErrorBoundary>
<div className="page">
<div
className={classNames({
staging: process.env.SCRATCH_ENV === 'staging'
})}
id="navigation"
>
<Navigation />
</div>
<div id="view">
{props.children}
</div>
<div id="footer">
<Footer />
</div>
</div>
<div id="view">
{props.children}
</div>
<div id="footer">
<Footer />
</div>
</div>
</ErrorBoundary>
);
Page.propTypes = {

View file

@ -2,6 +2,7 @@
"general.accountSettings": "Account settings",
"general.about": "About",
"general.aboutScratch": "About Scratch",
"general.back": "Back",
"general.birthMonth": "Birth Month",
"general.birthYear": "Birth Year",
"general.donate": "Donate",
@ -73,6 +74,7 @@
"general.tips": "Tips",
"general.tipsWindow": "Tips Window",
"general.termsOfUse": "Terms of Use",
"general.unhandledError": "We are so sorry, but it looks like Scratch has crashed. This bug has been automatically reported to the Scratch Team.",
"general.username": "Username",
"general.validationEmail": "Please enter a valid email address",
"general.validationEmailMatch": "The emails do not match",

BIN
static/images/unhandled.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB