merge with 2.0.0-m3

This commit is contained in:
Sebastian Sdorra
2018-12-10 14:36:10 +01:00
35 changed files with 1040 additions and 95 deletions

View File

@@ -1,8 +1,9 @@
// @flow
import {contextPath} from "./urls";
export const NOT_FOUND_ERROR_MESSAGE = "not found";
export const UNAUTHORIZED_ERROR_MESSAGE = "unauthorized";
export const NOT_FOUND_ERROR = new Error("not found");
export const UNAUTHORIZED_ERROR = new Error("unauthorized");
export const CONFLICT_ERROR = new Error("conflict");
const fetchOptions: RequestOptions = {
credentials: "same-origin",
@@ -15,24 +16,26 @@ function handleStatusCode(response: Response) {
if (!response.ok) {
switch (response.status) {
case 401:
return throwErrorWithMessage(response, UNAUTHORIZED_ERROR_MESSAGE);
return throwError(response, UNAUTHORIZED_ERROR);
case 404:
return throwErrorWithMessage(response, NOT_FOUND_ERROR_MESSAGE);
return throwError(response, NOT_FOUND_ERROR);
case 409:
return throwError(response, CONFLICT_ERROR);
default:
return throwErrorWithMessage(response, "server returned status code " + response.status);
return throwError(response, new Error("server returned status code " + response.status));
}
}
return response;
}
function throwErrorWithMessage(response: Response, message: string) {
function throwError(response: Response, err: Error) {
return response.json().then(
json => {
throw Error(json.message);
},
() => {
throw Error(message);
throw err;
}
);
}

View File

@@ -25,7 +25,7 @@ export { default as Tooltip } from "./Tooltip";
export { getPageFromMatch } from "./urls";
export { default as Autocomplete} from "./Autocomplete";
export { apiClient, NOT_FOUND_ERROR_MESSAGE, UNAUTHORIZED_ERROR_MESSAGE } from "./apiclient.js";
export { apiClient, NOT_FOUND_ERROR, UNAUTHORIZED_ERROR, CONFLICT_ERROR } from "./apiclient.js";
export * from "./avatar";
export * from "./buttons";