Files
SCM-Manager/scm-ui-components/packages/ui-components/src/ErrorNotification.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

//@flow
import React from "react";
import { translate } from "react-i18next";
2019-03-04 11:49:12 +01:00
import { BackendError, ForbiddenError, UnauthorizedError } from "./errors";
import Notification from "./Notification";
import BackendErrorNotification from "./BackendErrorNotification";
type Props = {
t: string => string,
error?: Error
};
2018-11-15 21:39:08 +01:00
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">
<strong>{t("error-notification.prefix")}:</strong>{" "}
{t("error-notification.timeout")}{" "}
<a href="javascript:window.location.reload(true)">
{t("error-notification.loginLink")}
</a>
</Notification>
);
2019-03-04 11:49:12 +01:00
} else if (error instanceof ForbiddenError) {
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong>{" "}
{t("error-notification.forbidden")}
</Notification>
)
} else
{
2018-12-12 13:35:58 +01:00
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong> {error.message}
</Notification>
);
}
}
2018-11-19 10:31:01 +01:00
return null;
}
}
export default translate("commons")(ErrorNotification);