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

49 lines
1.4 KiB
JavaScript
Raw Normal View History

//@flow
import React from "react";
2019-08-15 10:51:36 +02:00
import {translate} from "react-i18next";
import {BackendError, ForbiddenError, UnauthorizedError} from "./errors";
import Notification from "./Notification";
import BackendErrorNotification from "./BackendErrorNotification";
type Props = {
t: 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">
<strong>{t("errorNotification.prefix")}:</strong>{" "}
{t("errorNotification.timeout")}{" "}
2019-02-26 08:37:00 +01:00
<a href="javascript:window.location.reload(true)">
{t("errorNotification.loginLink")}
2019-02-26 08:37:00 +01:00
</a>
</Notification>
);
2019-03-04 11:49:12 +01:00
} else if (error instanceof ForbiddenError) {
return (
<Notification type="danger">
<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);