Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [html5] log out failed url.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRaindrop committed Jul 28, 2017
1 parent 84773cc commit 2b49e64
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,21 @@ function getContent(url) {
return new Promise((resolve, reject) => {
// select http or https module, depending on reqested url
const lib = url.startsWith('https') ? require('https') : require('http');
const request = lib.get(url, (response) => {
// handle http errors
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error('Failed to load page, status code: ' + response.statusCode));
}
// temporary data holder
const body = [];
// on every content chunk, push it to the data array
response.on('data', (chunk) => body.push(chunk));
// we are done, resolve promise with those joined chunks
response.on('end', () => resolve(body.join('')));
});
const request = lib.get(url, (function (url) {
return (response) => {
// handle http errors
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error('Failed to load page, status code: ' + response.statusCode + ', '
+ ' url: ' + url));
}
// temporary data holder
const body = [];
// on every content chunk, push it to the data array
response.on('data', (chunk) => body.push(chunk));
// we are done, resolve promise with those joined chunks
response.on('end', () => resolve(body.join('')));
}
})(url));
// handle connection errors of the request
request.on('error', (err) => reject(err))
})
Expand Down

0 comments on commit 2b49e64

Please sign in to comment.