Files
SCM-Manager/scm-ui/ui-components/src/ErrorNotification.tsx

44 lines
1.4 KiB
TypeScript
Raw Normal View History

import React from "react";
import { translate } from "react-i18next";
import { BackendError, ForbiddenError, UnauthorizedError } from "./errors";
import Notification from "./Notification";
import BackendErrorNotification from "./BackendErrorNotification";
type Props = {
t: (p: string) => string;
error?: Error;
};
class ErrorNotification extends React.Component<Props> {
render() {
const { t, error } = this.props;
if (error) {
2019-02-25 16:53:25 +01:00
if (error instanceof BackendError) {
return <BackendErrorNotification error={error} />;
2019-02-26 08:37:00 +01:00
} else if (error instanceof UnauthorizedError) {
return (
<Notification type="danger">
2019-10-21 10:57:56 +02:00
<strong>{t("errorNotification.prefix")}:</strong> {t("errorNotification.timeout")}{" "}
<a href="javascript:window.location.reload(true)">{t("errorNotification.loginLink")}</a>
2019-02-26 08:37:00 +01:00
</Notification>
);
2019-03-04 11:49:12 +01:00
} else if (error instanceof ForbiddenError) {
return (
<Notification type="danger">
2019-10-21 10:57:56 +02:00
<strong>{t("errorNotification.prefix")}:</strong> {t("errorNotification.forbidden")}
2019-03-04 11:49:12 +01:00
</Notification>
);
} else {
2018-12-12 13:35:58 +01:00
return (
<Notification type="danger">
<strong>{t("errorNotification.prefix")}:</strong> {error.message}
2018-12-12 13:35:58 +01:00
</Notification>
);
}
}
2018-11-19 10:31:01 +01:00
return null;
}
}
export default translate("commons")(ErrorNotification);