mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
Update version within PUT request
Try to add api logic check for version being the same instead of smaller implementing optimistic locking and displaying correct message in frontend rector fixes adjust violation message and add translation in translation.yaml add translator in apiController
This commit is contained in:
@@ -55,11 +55,20 @@ export interface ServerExceptionInterface extends TransportExceptionInterface {
|
||||
body: string;
|
||||
}
|
||||
|
||||
export interface ConflictHttpExceptionInterface extends TransportExceptionInterface {
|
||||
name: 'ConflictHttpException';
|
||||
violations: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic api method that can be adapted to any fetch request
|
||||
*/
|
||||
export const makeFetch = <Input, Output>(method: 'POST'|'GET'|'PUT'|'PATCH'|'DELETE', url: string, body?: body | Input | null, options?: FetchParams): Promise<Output> => {
|
||||
export const makeFetch = <Input, Output>(
|
||||
method: 'POST'|'GET'|'PUT'|'PATCH'|'DELETE',
|
||||
url: string, body?: body | Input | null,
|
||||
options?: FetchParams
|
||||
): Promise<Output> => {
|
||||
|
||||
let opts = {
|
||||
method: method,
|
||||
headers: {
|
||||
@@ -67,6 +76,7 @@ export const makeFetch = <Input, Output>(method: 'POST'|'GET'|'PUT'|'PATCH'|'DEL
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
if (body !== null && typeof body !== 'undefined') {
|
||||
Object.assign(opts, {body: JSON.stringify(body)})
|
||||
}
|
||||
@@ -90,6 +100,10 @@ export const makeFetch = <Input, Output>(method: 'POST'|'GET'|'PUT'|'PATCH'|'DEL
|
||||
throw AccessException(response);
|
||||
}
|
||||
|
||||
if (response.status === 409) {
|
||||
throw ConflictHttpException(response);
|
||||
}
|
||||
|
||||
throw {
|
||||
name: 'Exception',
|
||||
sta: response.status,
|
||||
@@ -220,3 +234,12 @@ const ServerException = (code: number, body: string): ServerExceptionInterface =
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
const ConflictHttpException = (response: Response): ConflictHttpExceptionInterface => {
|
||||
const error = {} as ConflictHttpExceptionInterface;
|
||||
|
||||
error.name = 'ConflictHttpException';
|
||||
error.violations = ['Sorry, but someone else has already changed this entity. Please refresh the page and apply the changes again']
|
||||
|
||||
return error;
|
||||
}
|
||||
|
Reference in New Issue
Block a user