Created
May 24, 2019 17:15
-
-
Save jrobinsonc/dc8bbe1a8a120132a5c888e6502a262d to your computer and use it in GitHub Desktop.
This file contains 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 fetch = options => | |
new Promise((resolve, reject) => { | |
require('https').get(options, function(response) { | |
let body = ''; | |
if (response.statusCode !== 200) { | |
reject( | |
new Error(`Request failed. Status code: ${response.statusCode}`), | |
); | |
response.resume(); | |
return; | |
} | |
response.on('error', err => reject(err)); | |
response.on('data', chunk => (body += chunk)); | |
response.on('end', () => resolve(body)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment