import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { getEnvironmentType } from '../../../app/scripts/lib/util';
import { ENVIRONMENT_TYPE_POPUP } from '../../../shared/constants/app';
import { SUPPORT_REQUEST_LINK } from '../../helpers/constants/common';
import {
EVENT,
EVENT_NAMES,
CONTEXT_PROPS,
} from '../../../shared/constants/metametrics';
class ErrorPage extends PureComponent {
static contextTypes = {
t: PropTypes.func.isRequired,
trackEvent: PropTypes.func,
};
static propTypes = {
error: PropTypes.object.isRequired,
};
renderErrorDetail(content) {
return (
{content}
);
}
renderErrorStack(title, stack) {
return (
{title}
{stack}
);
}
render() {
const { error } = this.props;
const { t } = this.context;
const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP;
const supportLink = (
{
this.context.trackEvent(
{
category: EVENT.CATEGORIES.ERROR,
event: EVENT_NAMES.SUPPORT_LINK_CLICKED,
properties: {
url: SUPPORT_REQUEST_LINK,
},
},
{
contextPropsIntoEventProperties: [CONTEXT_PROPS.PAGE_TITLE],
},
);
}}
>
{this.context.t('here')}
);
const message = isPopup
? t('errorPagePopupMessage', [supportLink])
: t('errorPageMessage', [supportLink]);
return (
{t('errorPageTitle')}
{message}
{t('errorDetails')}
{error.message
? this.renderErrorDetail(t('errorMessage', [error.message]))
: null}
{error.code
? this.renderErrorDetail(t('errorCode', [error.code]))
: null}
{error.name
? this.renderErrorDetail(t('errorName', [error.name]))
: null}
{error.stack
? this.renderErrorStack(t('errorStack'), error.stack)
: null}
);
}
}
export default ErrorPage;