Added ui error handling for 403 errors

This commit is contained in:
Philipp Czora
2019-03-04 11:49:12 +01:00
parent f68398e599
commit 6c06352de2
6 changed files with 28 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
//@flow
import React from "react";
import { translate } from "react-i18next";
import { BackendError, UnauthorizedError } from "./errors";
import { BackendError, ForbiddenError, UnauthorizedError } from "./errors";
import Notification from "./Notification";
import BackendErrorNotification from "./BackendErrorNotification";
@@ -27,7 +27,15 @@ class ErrorNotification extends React.Component<Props> {
</a>
</Notification>
);
} else {
} else if (error instanceof ForbiddenError) {
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong>{" "}
{t("error-notification.forbidden")}
</Notification>
)
} else
{
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong> {error.message}

View File

@@ -1,7 +1,7 @@
//@flow
import React from "react";
import ErrorNotification from "./ErrorNotification";
import { BackendError } from "./errors";
import { BackendError, ForbiddenError } from "./errors";
type Props = {
error: Error,
@@ -26,7 +26,7 @@ class ErrorPage extends React.Component<Props> {
renderSubtitle = () => {
const { error, subtitle } = this.props;
if (error instanceof BackendError) {
if (error instanceof BackendError || error instanceof ForbiddenError) {
return null;
}
return <p className="subtitle">{subtitle}</p>

View File

@@ -1,6 +1,6 @@
// @flow
import { contextPath } from "./urls";
import {createBackendError, isBackendError, UnauthorizedError} from "./errors";
import { createBackendError, ForbiddenError, isBackendError, UnauthorizedError } from "./errors";
import type { BackendErrorContent } from "./errors";
const fetchOptions: RequestOptions = {
@@ -22,7 +22,10 @@ function handleFailure(response: Response) {
} else {
if (response.status === 401) {
throw new UnauthorizedError("Unauthorized", 401);
} else if (response.status === 403) {
throw new ForbiddenError("Forbidden", 403);
}
throw new Error("server returned status code " + response.status);
}
}

View File

@@ -39,6 +39,14 @@ export class UnauthorizedError extends Error {
}
}
export class ForbiddenError extends Error {
statusCode: number;
constructor(message: string, statusCode: number) {
super(message);
this.statusCode = statusCode;
}
}
export class NotFoundError extends BackendError {
constructor(content: BackendErrorContent, statusCode: number) {
super(content, "NotFoundError", statusCode);