bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/error-screen/component.jsx

110 lines
2.5 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
2017-03-11 04:47:23 +08:00
import { defineMessages, injectIntl } from 'react-intl';
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import AudioManager from '/imports/ui/services/audio-manager';
import logger from '/imports/startup/client/logger';
import { styles } from './styles';
2017-03-11 04:47:23 +08:00
const intlMessages = defineMessages({
500: {
id: 'app.error.500',
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',
},
408: {
id: 'app.error.408',
},
2017-03-11 04:47:23 +08:00
404: {
id: 'app.error.404',
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
},
400: {
id: 'app.error.400',
},
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,
};
class ErrorScreen extends PureComponent {
componentDidMount() {
const { code } = this.props;
AudioManager.exitAudio();
Meteor.disconnect();
logger.error({ logCode: 'startup_client_usercouldnotlogin_error' }, `User could not log in HTML5, hit ${code}`);
}
2017-03-11 04:47:23 +08:00
render() {
const {
intl,
code,
children,
} = this.props;
2017-03-11 04:47:23 +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]);
}
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}>
<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
{
!errorMessageDescription || (
2020-06-19 20:49:07 +08:00
<div className={styles.sessionMessage}>
{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>
);
}
}
export default injectIntl(ErrorScreen);
2017-03-11 04:47:23 +08:00
ErrorScreen.propTypes = propTypes;
ErrorScreen.defaultProps = defaultProps;