2019-10-20 16:59:02 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import { BackendError, ForbiddenError, UnauthorizedError } from "./errors";
|
|
|
|
|
import Notification from "./Notification";
|
|
|
|
|
import BackendErrorNotification from "./BackendErrorNotification";
|
2018-09-03 16:17:36 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
|
|
|
|
error?: Error;
|
2018-09-03 16:17:36 +02:00
|
|
|
};
|
|
|
|
|
|
2019-02-26 17:08:33 +01:00
|
|
|
class ErrorNotification extends React.Component<Props> {
|
2018-09-03 16:17:36 +02:00
|
|
|
render() {
|
|
|
|
|
const { t, error } = this.props;
|
|
|
|
|
if (error) {
|
2019-02-25 16:53:25 +01:00
|
|
|
if (error instanceof BackendError) {
|
2019-06-11 18:10:29 +02:00
|
|
|
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>
|
2019-06-11 18:10:29 +02:00
|
|
|
);
|
|
|
|
|
} else {
|
2018-12-12 13:35:58 +01:00
|
|
|
return (
|
|
|
|
|
<Notification type="danger">
|
2019-10-20 16:59:02 +02:00
|
|
|
<strong>{t("errorNotification.prefix")}:</strong> {error.message}
|
2018-12-12 13:35:58 +01:00
|
|
|
</Notification>
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-09-03 16:17:36 +02:00
|
|
|
}
|
2018-11-19 10:31:01 +01:00
|
|
|
return null;
|
2018-09-03 16:17:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
export default translate("commons")(ErrorNotification);
|