Created
December 6, 2018 04:08
-
-
Save davidnguyen11/e4118cbd1373c9bd3d5cd57eaf701d29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'isomorphic-fetch' | |
| function handleData(response) { | |
| return new Promise((resolve, reject) => { | |
| console.log(response) | |
| const status = response.status | |
| return response.json().then(data => { | |
| const result = { | |
| ...data, | |
| status | |
| } | |
| if (status >= 200 && status < 300) { | |
| return resolve(result) | |
| } | |
| return reject(result) | |
| }) | |
| }) | |
| } | |
| export default function request(url, options) { | |
| return fetch(url, options) | |
| .then(handleData) | |
| .then(data => data) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment