(response)
| 1 | import newError from './errors' |
| 2 | |
| 3 | export default function handleResponse(response) { |
| 4 | if (response.headers.get('content-length') === '0' || response.status === 204) { |
| 5 | return |
| 6 | } |
| 7 | |
| 8 | const json = response.json() // TODO: support other response types |
| 9 | |
| 10 | if (response.status >= 200 && response.status < 300) { // TODO: support custom acceptable statuses |
| 11 | return json |
| 12 | } else { |
| 13 | return json.then(cause => Promise.reject(newError(cause))) |
| 14 | } |
| 15 | } |