fix: don't bail on corrupted URLs

Fixes #104

It will warn about them, but not fail the job, instead replacing the URL with '' (which is just as bad as the corrupted url, but at least it finishes).
This commit is contained in:
Remy Sharp 2016-07-31 14:15:28 +01:00
parent 0ae1301641
commit 0772d51069
3 changed files with 10 additions and 4 deletions

View File

@ -68,13 +68,17 @@ module.exports = function get(url, options) {
request(encodeURI(url), settings, function response(error, res, body) {
if (error) {
debug('request failed: %s', error.message);
return reject(error);
inliner.emit('warning', 'failed to request ' + base + ' (' + error.message + ')');
// return reject(error);
body = '';
res = {
headers: {},
};
} else if (res.statusCode !== 200) {
inliner.emit('warning', res.statusCode + ' on ' + base);
}
debug('response: %s %s', res.statusCode, url);
if (res.statusCode !== 200) {
inliner.emit('warning', res.statusCode + ' on ' + base);
}
if (res.statusCode >= 400) {
body = '';

1
test/fixtures/bad-url.result.html vendored Normal file
View File

@ -0,0 +1 @@
<img src="data:undefined;base64,">

1
test/fixtures/bad-url.src.html vendored Normal file
View File

@ -0,0 +1 @@
<img src="http:////l.yimg.com//ts//api//res//1.2//a7RcmRbkGrGLwQ2v.eoRUQ--//YXBwaWQ9eWhvbWVydW47cT00MDtzbT0xO3c9NjAwO2g9MTI1NA--//https:////s.yimg.com//av//moneyball//ads//1465557018638-5668.jpg">