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';
|
2021-10-28 03:51:43 +08:00
|
|
|
import Styled from './styles';
|
2017-03-11 04:47:23 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
2022-10-14 21:27:23 +08:00
|
|
|
503: {
|
|
|
|
id: 'app.error.503',
|
|
|
|
},
|
2017-03-11 04:47:23 +08:00
|
|
|
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',
|
|
|
|
},
|
2022-10-14 21:27:23 +08:00
|
|
|
409: {
|
|
|
|
id: 'app.error.409',
|
|
|
|
},
|
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',
|
|
|
|
},
|
2022-05-14 03:18:51 +08:00
|
|
|
joined_another_window_reason: {
|
|
|
|
id: 'app.error.joinedAnotherWindow',
|
|
|
|
},
|
2022-08-16 01:59:58 +08:00
|
|
|
user_inactivity_eject_reason: {
|
|
|
|
id: 'app.meeting.logout.userInactivityEjectReason',
|
|
|
|
},
|
2022-09-23 01:22:58 +08:00
|
|
|
user_requested_eject_reason: {
|
|
|
|
id: 'app.meeting.logout.ejectedFromMeeting',
|
|
|
|
},
|
|
|
|
duplicate_user_in_meeting_eject_reason: {
|
|
|
|
id: 'app.meeting.logout.duplicateUserEjectReason',
|
|
|
|
},
|
|
|
|
not_enough_permission_eject_reason: {
|
|
|
|
id: 'app.meeting.logout.permissionEjectReason',
|
|
|
|
},
|
2022-10-14 21:27:23 +08:00
|
|
|
able_to_rejoin_user_disconnected_reason: {
|
|
|
|
id: 'app.error.disconnected.rejoin',
|
|
|
|
},
|
2017-03-11 04:47:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
code: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
2022-10-18 00:35:23 +08:00
|
|
|
code: '500',
|
2022-10-14 21:27:23 +08:00
|
|
|
callback: async () => {},
|
2017-03-11 04:47:23 +08:00
|
|
|
};
|
|
|
|
|
2020-06-03 03:47:26 +08:00
|
|
|
class ErrorScreen extends PureComponent {
|
2018-11-05 23:48:57 +08:00
|
|
|
componentDidMount() {
|
2022-10-14 21:27:23 +08:00
|
|
|
const { code, callback } = this.props;
|
2022-10-18 00:35:23 +08:00
|
|
|
const log = code === '403' ? 'warn' : 'error';
|
2020-06-03 03:47:26 +08:00
|
|
|
AudioManager.exitAudio();
|
2022-10-14 21:27:23 +08:00
|
|
|
callback().finally(() => {
|
|
|
|
Meteor.disconnect();
|
|
|
|
});
|
2022-01-15 04:47:34 +08:00
|
|
|
logger[log]({ 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');
|
|
|
|
|
2022-10-14 21:27:23 +08:00
|
|
|
if (errorMessageDescription in intlMessages) {
|
2021-03-30 21:09:25 +08:00
|
|
|
errorMessageDescription = intl.formatMessage(intlMessages[errorMessageDescription]);
|
|
|
|
}
|
|
|
|
|
2017-03-11 04:47:23 +08:00
|
|
|
return (
|
2021-10-28 03:51:43 +08:00
|
|
|
<Styled.Background>
|
|
|
|
<Styled.Message data-test="errorScreenMessage">
|
2017-03-11 04:47:23 +08:00
|
|
|
{formatedMessage}
|
2021-10-28 03:51:43 +08:00
|
|
|
</Styled.Message>
|
2019-01-08 00:26:23 +08:00
|
|
|
{
|
2022-09-23 01:22:58 +08:00
|
|
|
!errorMessageDescription
|
|
|
|
|| formatedMessage === errorMessageDescription
|
|
|
|
|| (
|
2021-10-28 03:51:43 +08:00
|
|
|
<Styled.SessionMessage>
|
2021-03-30 21:09:25 +08:00
|
|
|
{errorMessageDescription}
|
2021-10-28 03:51:43 +08:00
|
|
|
</Styled.SessionMessage>
|
|
|
|
)
|
2019-01-08 00:26:23 +08:00
|
|
|
}
|
2021-10-28 03:51:43 +08:00
|
|
|
<Styled.Separator />
|
|
|
|
<Styled.CodeError>
|
2020-06-19 20:49:07 +08:00
|
|
|
{code}
|
2021-10-28 03:51:43 +08:00
|
|
|
</Styled.CodeError>
|
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>
|
2021-10-28 03:51:43 +08:00
|
|
|
</Styled.Background>
|
2017-03-11 04:47:23 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|