mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 05:55:44 +01:00
correct error throwing in apiclient and add extension point
This commit is contained in:
@@ -16,30 +16,19 @@ function handleStatusCode(response: Response) {
|
||||
if (!response.ok) {
|
||||
switch (response.status) {
|
||||
case 401:
|
||||
return throwError(response, UNAUTHORIZED_ERROR);
|
||||
throw UNAUTHORIZED_ERROR;
|
||||
case 404:
|
||||
return throwError(response, NOT_FOUND_ERROR);
|
||||
throw NOT_FOUND_ERROR;
|
||||
case 409:
|
||||
return throwError(response, CONFLICT_ERROR);
|
||||
throw CONFLICT_ERROR;
|
||||
default:
|
||||
return throwError(response, new Error("server returned status code " + response.status));
|
||||
throw new Error("server returned status code " + response.status);
|
||||
}
|
||||
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
function throwError(response: Response, err: Error) {
|
||||
return response.json().then(
|
||||
json => {
|
||||
throw Error(json.message);
|
||||
},
|
||||
() => {
|
||||
throw err;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function createUrl(url: string) {
|
||||
if (url.includes("://")) {
|
||||
return url;
|
||||
|
||||
Reference in New Issue
Block a user