vue_visgraph: makeFetch (api), add validation exception

This commit is contained in:
Mathieu Jaumotte 2021-10-29 10:01:14 +02:00
parent 998295dc5f
commit 76d6a9b4df

View File

@ -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)
}