2020-06-03 03:47:26 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-06-04 10:40:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-03-11 04:47:23 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2018-11-05 23:48:57 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2020-06-03 03:47:26 +08:00
|
|
|
import { Session } from 'meteor/session';
|
|
|
|
import AudioManager from '/imports/ui/services/audio-manager';
|
2018-01-17 02:26:57 +08:00
|
|
|
import { styles } from './styles';
|
2017-03-11 04:47:23 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
500: {
|
|
|
|
id: 'app.error.500',
|
2020-02-07 04:47:28 +08:00
|
|
|
defaultMessage: 'Oops, something went wrong',
|
2017-03-11 04:47:23 +08:00
|
|
|
},
|
2019-04-27 01:52:18 +08:00
|
|
|
410: {
|
|
|
|
id: 'app.error.410',
|
|
|
|
},
|
2017-03-11 04:47:23 +08:00
|
|
|
404: {
|
|
|
|
id: 'app.error.404',
|
2017-04-15 07:26:34 +08:00
|
|
|
defaultMessage: 'Not found',
|
2017-03-11 04:47:23 +08:00
|
|
|
},
|
2019-04-27 01:14:37 +08:00
|
|
|
403: {
|
|
|
|
id: 'app.error.403',
|
|
|
|
},
|
2017-03-11 04:47:23 +08:00
|
|
|
401: {
|
2017-04-18 01:14:31 +08:00
|
|
|
id: 'app.error.401',
|
2017-03-11 04:47:23 +08:00
|
|
|
},
|
2019-01-09 02:38:26 +08:00
|
|
|
400: {
|
|
|
|
id: 'app.error.400',
|
|
|
|
},
|
2017-03-11 04:47:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
code: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
code: 500,
|
|
|
|
};
|
|
|
|
|
2020-06-03 03:47:26 +08:00
|
|
|
class ErrorScreen extends PureComponent {
|
2018-11-05 23:48:57 +08:00
|
|
|
componentDidMount() {
|
2020-06-03 03:47:26 +08:00
|
|
|
AudioManager.exitAudio();
|
2018-11-05 23:48:57 +08:00
|
|
|
Meteor.disconnect();
|
|
|
|
}
|
|
|
|
|
2017-03-11 04:47:23 +08:00
|
|
|
render() {
|
2017-12-12 21:08:43 +08:00
|
|
|
const {
|
2018-10-04 00:14:10 +08:00
|
|
|
intl,
|
|
|
|
code,
|
|
|
|
children,
|
2017-12-12 21:08:43 +08:00
|
|
|
} = this.props;
|
2017-03-11 04:47:23 +08:00
|
|
|
|
2017-12-12 21:08:43 +08:00
|
|
|
let formatedMessage = intl.formatMessage(intlMessages[defaultProps.code]);
|
2017-03-11 04:47:23 +08:00
|
|
|
|
|
|
|
if (code in intlMessages) {
|
|
|
|
formatedMessage = intl.formatMessage(intlMessages[code]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.background}>
|
|
|
|
<h1 className={styles.message}>
|
|
|
|
{formatedMessage}
|
|
|
|
</h1>
|
2019-01-08 00:26:23 +08:00
|
|
|
{
|
2019-01-09 02:38:26 +08:00
|
|
|
!Session.get('errorMessageDescription') || (
|
2020-06-19 20:49:07 +08:00
|
|
|
<div className={styles.sessionMessage}>
|
|
|
|
{Session.get('errorMessageDescription')}
|
|
|
|
</div>)
|
2019-01-08 00:26:23 +08:00
|
|
|
}
|
|
|
|
<div className={styles.separator} />
|
2020-06-19 20:49:07 +08:00
|
|
|
<h1 className={styles.codeError}>
|
|
|
|
{code}
|
|
|
|
</h1>
|
2018-12-06 01:42:31 +08:00
|
|
|
<div>
|
2017-03-11 04:47:23 +08:00
|
|
|
{children}
|
2017-04-29 04:16:07 +08:00
|
|
|
</div>
|
2017-03-11 04:47:23 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 00:14:10 +08:00
|
|
|
export default injectIntl(ErrorScreen);
|
2017-03-11 04:47:23 +08:00
|
|
|
|
|
|
|
ErrorScreen.propTypes = propTypes;
|
|
|
|
ErrorScreen.defaultProps = defaultProps;
|