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