From 76d6a9b4dfe2943cf5ff3bf6301edeba7b18e187 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 29 Oct 2021 10:01:14 +0200 Subject: [PATCH] vue_visgraph: makeFetch (api), add validation exception --- .../Resources/public/vuejs/VisGraph/api.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/api.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/api.js index f595daa34..5533bd6ff 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/api.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/api.js @@ -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} */ const getFetch = (url) => { - return makeFetch('GET', url, null); + return makeFetch('GET', url, null) } /** @@ -49,7 +60,7 @@ const getFetch = (url) => { * @returns {Promise} */ const postFetch = (url, body) => { - return makeFetch('POST', url, body); + return makeFetch('POST', url, body) } /** @@ -59,7 +70,7 @@ const postFetch = (url, body) => { * @returns {Promise} */ const patchFetch = (url, body) => { - return makeFetch('PATCH', url, body); + return makeFetch('PATCH', url, body) }