2020-01-24 22:11:02 +01:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
|
|
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../../app/scripts/lib/enums'
|
|
|
|
|
|
|
|
class ErrorPage extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
error: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderErrorDetail(content) {
|
2020-01-24 22:11:02 +01:00
|
|
|
return (
|
|
|
|
<li>
|
2020-11-03 00:41:28 +01:00
|
|
|
<p>{content}</p>
|
2020-01-24 22:11:02 +01:00
|
|
|
</li>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderErrorStack(title, stack) {
|
2020-01-24 22:11:02 +01:00
|
|
|
return (
|
|
|
|
<li>
|
2020-11-03 00:41:28 +01:00
|
|
|
<span>{title}</span>
|
|
|
|
<pre className="error-page__stack">{stack}</pre>
|
2020-01-24 22:11:02 +01:00
|
|
|
</li>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2020-01-24 22:11:02 +01:00
|
|
|
const { error } = this.props
|
|
|
|
const { t } = this.context
|
|
|
|
|
|
|
|
const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP
|
|
|
|
|
|
|
|
return (
|
|
|
|
<section className="error-page">
|
2020-11-03 00:41:28 +01:00
|
|
|
<h1 className="error-page__header">{t('errorPageTitle')}</h1>
|
2020-01-24 22:11:02 +01:00
|
|
|
<h2 className="error-page__subheader">
|
2020-11-03 00:41:28 +01:00
|
|
|
{isPopup ? t('errorPagePopupMessage') : t('errorPageMessage')}
|
2020-01-24 22:11:02 +01:00
|
|
|
</h2>
|
|
|
|
<section className="error-page__details">
|
|
|
|
<details>
|
2020-11-03 00:41:28 +01:00
|
|
|
<summary>{t('errorDetails')}</summary>
|
2020-01-24 22:11:02 +01:00
|
|
|
<ul>
|
2020-11-03 00:41:28 +01:00
|
|
|
{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}
|
2020-01-24 22:11:02 +01:00
|
|
|
</ul>
|
|
|
|
</details>
|
|
|
|
</section>
|
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ErrorPage
|