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) { if (response.status === 422) {
return response.json(); return response.json().then(violations => {
throw ValidationException(violations)
});
} }
throw { throw {
@ -33,13 +35,22 @@ const makeFetch = (method, url, body) => {
}); });
} }
/**
* @param violations
* @constructor
*/
const ValidationException = (violations) => {
this.violations = violations
this.name = 'ValidationException'
}
/** /**
* @function getFetch * @function getFetch
* @param url * @param url
* @returns {Promise<Response>} * @returns {Promise<Response>}
*/ */
const getFetch = (url) => { const getFetch = (url) => {
return makeFetch('GET', url, null); return makeFetch('GET', url, null)
} }
/** /**
@ -49,7 +60,7 @@ const getFetch = (url) => {
* @returns {Promise<Response>} * @returns {Promise<Response>}
*/ */
const postFetch = (url, body) => { 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>} * @returns {Promise<Response>}
*/ */
const patchFetch = (url, body) => { const patchFetch = (url, body) => {
return makeFetch('PATCH', url, body); return makeFetch('PATCH', url, body)
} }