66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
import React from "react";
|
|
import { withTranslation } from "react-i18next";
|
|
import { Result, Button, Collapse, Row, Col, Space } from "antd";
|
|
|
|
class ErrorBoundary extends React.Component {
|
|
constructor() {
|
|
super();
|
|
this.state = {
|
|
hasErrored: false,
|
|
error: null,
|
|
};
|
|
}
|
|
|
|
static getDerivedStateFromError(error) {
|
|
return { hasErrored: true, error };
|
|
}
|
|
|
|
componentDidCatch(error, info) {
|
|
console.log("Exception Caught by Error Boundary.", error, info);
|
|
}
|
|
|
|
render() {
|
|
const { t } = this.props;
|
|
if (this.state.hasErrored === true) {
|
|
return (
|
|
<div>
|
|
<Result
|
|
status='500'
|
|
title={t("general.labels.exceptiontitle")}
|
|
subTitle={t("general.messages.exception")}
|
|
extra={
|
|
<Space>
|
|
<Button
|
|
type='primary'
|
|
onClick={() => {
|
|
window.location.reload();
|
|
}}>
|
|
{t("general.actions.refresh")}
|
|
</Button>
|
|
<Button
|
|
onClick={() => {
|
|
alert("Not implemented yet.");
|
|
}}>
|
|
{t("general.actions.submitticket")}
|
|
</Button>
|
|
</Space>
|
|
}
|
|
/>
|
|
<Row>
|
|
<Col offset={6} span={12}>
|
|
<Collapse bordered={false}>
|
|
<Collapse.Panel header={t("general.labels.errors")}>
|
|
{JSON.stringify(this.state.error || "")}
|
|
</Collapse.Panel>
|
|
</Collapse>
|
|
</Col>
|
|
</Row>
|
|
</div>
|
|
);
|
|
} else {
|
|
return this.props.children;
|
|
}
|
|
}
|
|
}
|
|
export default withTranslation()(ErrorBoundary);
|