mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
Added ui error handling for 403 errors
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user