2018-09-03 16:17:36 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
2019-08-15 10:51:36 +02:00
|
|
|
import {translate} from "react-i18next";
|
|
|
|
|
import {BackendError, ForbiddenError, UnauthorizedError} from "./errors";
|
2019-02-26 17:08:33 +01:00
|
|
|
import Notification from "./Notification";
|
|
|
|
|
import BackendErrorNotification from "./BackendErrorNotification";
|
2018-09-03 16:17:36 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
t: string => string,
|
|
|
|
|
error?: Error
|
|
|
|
|
};
|
|
|
|
|
|
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-06-11 18:10:29 +02:00
|
|
|
<strong>{t("errorNotification.prefix")}:</strong>{" "}
|
|
|
|
|
{t("errorNotification.timeout")}{" "}
|
2019-02-26 08:37:00 +01:00
|
|
|
<a href="javascript:window.location.reload(true)">
|
2019-06-11 18:10:29 +02:00
|
|
|
{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">
|
2019-06-11 18:10:29 +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-06-11 18:10:29 +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-06-11 18:10:29 +02:00
|
|
|
export default translate("commons")(ErrorNotification);
|