| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 2x 2x 2x | export const verifyStatus = response => { if (response.status >= 200 && response.status < 300) { return response; } const error = new Error(response.statusText); error.response = response; throw error; }; export const parseJSON = response => { if (response.status !== 204) { return response.json(); } return '{}'; }; export const makeRequest = (url, options = {}) => fetch(url, options).then(verifyStatus).then(parseJSON); |