/** * Check response to detect error. If so, throw the error object else return the response * @param {Promise<Object>} response the response promise produce by the fetch API * @throws {Object} an error produce by the API * @returns {Promise<Object>} the response promise produce by the fetch API */ function apiErrorManagement(response) { return !response.ok ? response.json().then((json) => { throw json; }) : response; }