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';
|
2020-08-03 20:44:21 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
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',
|
|
|
|
},
|
2020-10-08 03:50:17 +08:00
|
|
|
408: {
|
|
|
|
id: 'app.error.408',
|
|
|
|
},
|
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',
|
|
|
|
},
|
2021-03-30 21:09:25 +08:00
|
|
|
user_logged_out_reason: {
|
|
|
|
id: 'app.error.userLoggedOut',
|
|
|
|
},
|
|
|
|
validate_token_failed_eject_reason: {
|
|
|
|
id: 'app.error.ejectedUser',
|
|
|
|
},
|
|
|
|
banned_user_rejoining_reason: {
|
|
|
|
id: 'app.error.userBanned',
|
|
|
|
},
|
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-08-03 20:44:21 +08:00
|
|
|
const { code } = this.props;
|
2020-06-03 03:47:26 +08:00
|
|
|
AudioManager.exitAudio();
|
2018-11-05 23:48:57 +08:00
|
|
|
Meteor.disconnect();
|
2020-08-03 20:44:21 +08:00
|
|
|
logger.error({ logCode: 'startup_client_usercouldnotlogin_error' }, `User could not log in HTML5, hit ${code}`);
|
2018-11-05 23:48:57 +08:00
|
|
|
}
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2021-03-30 21:09:25 +08:00
|
|
|
let errorMessageDescription = Session.get('errorMessageDescription');
|
|
|
|
|
|
|
|
if (code === 403 && errorMessageDescription in intlMessages) {
|
|
|
|
errorMessageDescription = intl.formatMessage(intlMessages[errorMessageDescription]);
|
|
|
|
}
|
|
|
|
|
2017-03-11 04:47:23 +08:00
|
|
|
return (
|
|
|
|
<div className={styles.background}>
|
2021-06-08 09:20:07 +08:00
|
|
|
<h1 className={styles.message} data-test="errorScreenMessage">
|
2017-03-11 04:47:23 +08:00
|
|
|
{formatedMessage}
|
|
|
|
</h1>
|
2019-01-08 00:26:23 +08:00
|
|
|
{
|
2021-03-30 21:09:25 +08:00
|
|
|
!errorMessageDescription || (
|
2020-06-19 20:49:07 +08:00
|
|
|
<div className={styles.sessionMessage}>
|
2021-03-30 21:09:25 +08:00
|
|
|
{errorMessageDescription}
|
2020-06-19 20:49:07 +08:00
|
|
|
</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;
|