Created
October 31, 2017 20:20
-
-
Save tanepiper/da19a50ae03d22bf55058a6ef3eed1f4 to your computer and use it in GitHub Desktop.
Difference between old and new doRequest methods
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
const doRequest = async ({ accessToken, config, method, data }) => { | |
const uri = generateUrl(accessToken, method, data, config); | |
try { | |
const req = await request({ uri }); | |
return JSON.parse(req); | |
} catch (e) { | |
console.log('Request Failed'); | |
throw e; | |
} | |
}; |
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
doRequest (requestUri) { | |
return new Promise((resolve, reject) => { | |
return fetch(requestUri) | |
.then((response) => { | |
if (response.status >= 400) { | |
return reject(Boom.create(response.status, response.statusText, response)); | |
} | |
return resolve(response.json()); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment