mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
vue_visgraph: makeFetch (api), add validation exception
This commit is contained in:
parent
998295dc5f
commit
76d6a9b4df
@ -20,7 +20,9 @@ const makeFetch = (method, url, body) => {
|
||||
}
|
||||
|
||||
if (response.status === 422) {
|
||||
return response.json();
|
||||
return response.json().then(violations => {
|
||||
throw ValidationException(violations)
|
||||
});
|
||||
}
|
||||
|
||||
throw {
|
||||
@ -33,13 +35,22 @@ const makeFetch = (method, url, body) => {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param violations
|
||||
* @constructor
|
||||
*/
|
||||
const ValidationException = (violations) => {
|
||||
this.violations = violations
|
||||
this.name = 'ValidationException'
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getFetch
|
||||
* @param url
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
const getFetch = (url) => {
|
||||
return makeFetch('GET', url, null);
|
||||
return makeFetch('GET', url, null)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,7 +60,7 @@ const getFetch = (url) => {
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
const postFetch = (url, body) => {
|
||||
return makeFetch('POST', url, body);
|
||||
return makeFetch('POST', url, body)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +70,7 @@ const postFetch = (url, body) => {
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
const patchFetch = (url, body) => {
|
||||
return makeFetch('PATCH', url, body);
|
||||
return makeFetch('PATCH', url, body)
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user