mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
Added ui error handling for 403 errors
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
import { BackendError, UnauthorizedError } from "./errors";
|
import { BackendError, ForbiddenError, UnauthorizedError } from "./errors";
|
||||||
import Notification from "./Notification";
|
import Notification from "./Notification";
|
||||||
import BackendErrorNotification from "./BackendErrorNotification";
|
import BackendErrorNotification from "./BackendErrorNotification";
|
||||||
|
|
||||||
@@ -27,7 +27,15 @@ class ErrorNotification extends React.Component<Props> {
|
|||||||
</a>
|
</a>
|
||||||
</Notification>
|
</Notification>
|
||||||
);
|
);
|
||||||
} else {
|
} else if (error instanceof ForbiddenError) {
|
||||||
|
return (
|
||||||
|
<Notification type="danger">
|
||||||
|
<strong>{t("error-notification.prefix")}:</strong>{" "}
|
||||||
|
{t("error-notification.forbidden")}
|
||||||
|
</Notification>
|
||||||
|
)
|
||||||
|
} else
|
||||||
|
{
|
||||||
return (
|
return (
|
||||||
<Notification type="danger">
|
<Notification type="danger">
|
||||||
<strong>{t("error-notification.prefix")}:</strong> {error.message}
|
<strong>{t("error-notification.prefix")}:</strong> {error.message}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import ErrorNotification from "./ErrorNotification";
|
import ErrorNotification from "./ErrorNotification";
|
||||||
import { BackendError } from "./errors";
|
import { BackendError, ForbiddenError } from "./errors";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
error: Error,
|
error: Error,
|
||||||
@@ -26,7 +26,7 @@ class ErrorPage extends React.Component<Props> {
|
|||||||
|
|
||||||
renderSubtitle = () => {
|
renderSubtitle = () => {
|
||||||
const { error, subtitle } = this.props;
|
const { error, subtitle } = this.props;
|
||||||
if (error instanceof BackendError) {
|
if (error instanceof BackendError || error instanceof ForbiddenError) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return <p className="subtitle">{subtitle}</p>
|
return <p className="subtitle">{subtitle}</p>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { contextPath } from "./urls";
|
import { contextPath } from "./urls";
|
||||||
import {createBackendError, isBackendError, UnauthorizedError} from "./errors";
|
import { createBackendError, ForbiddenError, isBackendError, UnauthorizedError } from "./errors";
|
||||||
import type { BackendErrorContent } from "./errors";
|
import type { BackendErrorContent } from "./errors";
|
||||||
|
|
||||||
const fetchOptions: RequestOptions = {
|
const fetchOptions: RequestOptions = {
|
||||||
@@ -22,7 +22,10 @@ function handleFailure(response: Response) {
|
|||||||
} else {
|
} else {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
throw new UnauthorizedError("Unauthorized", 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);
|
throw new Error("server returned status code " + response.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
export class NotFoundError extends BackendError {
|
||||||
constructor(content: BackendErrorContent, statusCode: number) {
|
constructor(content: BackendErrorContent, statusCode: number) {
|
||||||
super(content, "NotFoundError", statusCode);
|
super(content, "NotFoundError", statusCode);
|
||||||
|
|||||||
@@ -23,7 +23,8 @@
|
|||||||
"prefix": "Fehler",
|
"prefix": "Fehler",
|
||||||
"loginLink": "Erneute Anmeldung",
|
"loginLink": "Erneute Anmeldung",
|
||||||
"timeout": "Die Session ist abgelaufen.",
|
"timeout": "Die Session ist abgelaufen.",
|
||||||
"wrong-login-credentials": "Ungültige Anmeldedaten"
|
"wrong-login-credentials": "Ungültige Anmeldedaten",
|
||||||
|
"forbidden": "Sie haben nicht die Berechtigung, diese Entität zu sehen"
|
||||||
},
|
},
|
||||||
"loading": {
|
"loading": {
|
||||||
"alt": "Lade ..."
|
"alt": "Lade ..."
|
||||||
|
|||||||
@@ -23,7 +23,8 @@
|
|||||||
"prefix": "Error",
|
"prefix": "Error",
|
||||||
"loginLink": "You can login here again.",
|
"loginLink": "You can login here again.",
|
||||||
"timeout": "The session has expired",
|
"timeout": "The session has expired",
|
||||||
"wrong-login-credentials": "Invalid credentials"
|
"wrong-login-credentials": "Invalid credentials",
|
||||||
|
"forbidden": "You don't have permission to view this entity"
|
||||||
},
|
},
|
||||||
"loading": {
|
"loading": {
|
||||||
"alt": "Loading ..."
|
"alt": "Loading ..."
|
||||||
|
|||||||
Reference in New Issue
Block a user