import React from "react"; import { BackendError } from "./errors"; import Notification from "./Notification"; import { WithTranslation, withTranslation } from "react-i18next"; type Props = WithTranslation & { error: BackendError; }; class BackendErrorNotification extends React.Component { constructor(props: Props) { super(props); } render() { return (

{this.renderErrorName()}

{this.renderErrorDescription()}

{this.renderViolations()}

{this.renderMetadata()}
); } renderErrorName = () => { const { error, t } = this.props; const translation = t("errors." + error.errorCode + ".displayName"); if (translation === error.errorCode) { return error.message; } return translation; }; renderErrorDescription = () => { const { error, t } = this.props; const translation = t("errors." + error.errorCode + ".description"); if (translation === error.errorCode) { return ""; } return translation; }; renderViolations = () => { const { error, t } = this.props; if (error.violations) { return ( <>

{t("errors.violations")}

); } }; renderMetadata = () => { const { error, t } = this.props; return ( <> {this.renderContext()} {this.renderMoreInformationLink()}
{t("errors.transactionId")} {error.transactionId}
{t("errors.errorCode")} {error.errorCode}
); }; renderContext = () => { const { error, t } = this.props; if (error.context) { return ( <>

{t("errors.context")}

); } }; renderMoreInformationLink = () => { const { error, t } = this.props; if (error.url) { return (

{t("errors.moreInfo")}{" "} {error.errorCode}

); } }; } export default withTranslation("plugins")(BackendErrorNotification);