(endpoint, method = 'get', body)
| 6 | '/api'; |
| 7 | |
| 8 | export default function callApi(endpoint, method = 'get', body) { |
| 9 | return fetch(`${API_URL}/${endpoint}`, { |
| 10 | headers: { 'content-type': 'application/json' }, |
| 11 | method, |
| 12 | body: JSON.stringify(body), |
| 13 | }) |
| 14 | .then(response => response.json().then(json => ({ json, response }))) |
| 15 | .then(({ json, response }) => { |
| 16 | if (!response.ok) { |
| 17 | return Promise.reject(json); |
| 18 | } |
| 19 | |
| 20 | return json; |
| 21 | }) |
| 22 | .then( |
| 23 | response => response, |
| 24 | error => error |
| 25 | ); |
| 26 | } |
no outgoing calls
no test coverage detected