Fixed 401 message on login

This commit is contained in:
Philipp Czora
2019-02-25 17:40:53 +01:00
parent 0814e0af7a
commit aac94d17a3
2 changed files with 19 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
// @flow
import { contextPath } from "./urls";
import { createBackendError } from "./errors";
import {createBackendError, isBackendError, UnauthorizedError} from "./errors";
import type { BackendErrorContent } from "./errors";
const fetchOptions: RequestOptions = {
@@ -10,9 +10,7 @@ const fetchOptions: RequestOptions = {
}
};
function isBackendError(response) {
return response.headers.get("Content-Type") === "application/vnd.scmm-error+json;v=2";
}
function handleFailure(response: Response) {
if (!response.ok) {
@@ -22,6 +20,9 @@ function handleFailure(response: Response) {
throw createBackendError(content, response.status);
});
} else {
if (response.status === 401) {
throw new UnauthorizedError("Unauthorized", 401);
}
throw new Error("server returned status code " + response.status);
}
}