Commit 853ad65d authored by Victor_Friboulet's avatar Victor_Friboulet
Browse files

simplification du fetchUtility

parent 040126b4
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -6,9 +6,6 @@
 * @return {object}          The parsed JSON from the request
 */
function parseJSON(response) {
    if (response.status === 204 || response.status === 205) {
        return null;
    }
    return response.json();
}

@@ -20,7 +17,7 @@ function parseJSON(response) {
 * @return {object|undefined} Returns either the response, or throws an error
 */
function checkStatus(response) {
    if (response.status >= 200 && response.status < 300) {
    if (response.ok) {
        return response;
    }

@@ -42,6 +39,10 @@ function checkStatus(response) {
function request(url, options) {
    return fetch(url, options)
        .then(checkStatus)
        .then(parseJSON);
        .then(parseJSON)
        .catch((error) => {
            console.log(error);
        })
        
}