@seasketch/geoprocessing
Version:
Geoprocessing and reporting framework for SeaSketch 2.0
36 lines • 1.29 kB
JavaScript
import React from "react";
import Card from "./Card.js";
import { useTranslation } from "react-i18next";
import PropTypes from "prop-types";
import { ErrorStatus } from "./ErrorStatus.js";
const ErrorCard = () => {
const { t } = useTranslation();
return (React.createElement(Card, null,
React.createElement("div", { role: "alert" },
React.createElement(ErrorStatus, { msg: React.createElement(React.Fragment, null, t("An error occurred while rendering this component. If the error persists, please report it.")) }))));
};
export class ReportError extends React.Component {
state = {
hasError: false,
error: { message: "", stack: "" },
info: { componentStack: "" },
};
static getDerivedStateFromError = () => {
return { hasError: true };
};
componentDidCatch = (error, info) => {
this.setState({ error, info });
};
static propTypes;
render() {
const { hasError, error, info } = this.state;
if (hasError)
console.info(error.message, info);
const { children } = this.props;
return hasError ? React.createElement(ErrorCard, null) : children;
}
}
ReportError.propTypes = {
children: PropTypes.node,
};
//# sourceMappingURL=ReportError.js.map