Skip to content

Commit

Permalink
fix: replace with empty string if error in GET
Browse files Browse the repository at this point in the history
Fixes #61

It seems to work, but I'm not sure if it's a clean way of doing it. Let
me know what you think @remy.
  • Loading branch information
Sam Nguyen committed Aug 29, 2015
1 parent 9904b6b commit 8af810f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/get.js
Expand Up @@ -54,12 +54,20 @@ module.exports = function get(url, options) {
return reject(error);
}

if (!res) {
res = { headers: {}, statusCode: null };
}

debug('response: %s %s', res.statusCode, url);
if (!error && res.statusCode === 200) {
resolve({ headers: res.headers, body: body });
} else {
return reject(new Error(res.statusCode));
if (res.statusCode !== 200) {
body = '';
}

resolve({
body: body,
headers: res.headers,
statusCode: res.statusCode,
});
});
});

Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Expand Up @@ -146,6 +146,10 @@ function main() {
var cheerioLoadOptions = {};
var enc = inliner.options.encoding;

if (res.statusCode !== 200) {
inliner.emit('progress', res.statusCode + ' on ' + url);
}

// try to determine the encoding from the headers and the body
if (!enc) {
enc = charset(res.headers, res.body);
Expand Down
5 changes: 5 additions & 0 deletions lib/javascript.js
Expand Up @@ -5,6 +5,11 @@ var UglifyJS = require('uglify-js');

function uglify(source) {
this.emit('progress', 'compressing javascript');

if (source.body === '') {
return '';
}

if (source.body) {
source = source.body;
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/get-error.result.html
@@ -0,0 +1 @@
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta charset="UTF-8"> <title>App</title> <style></style> <script></script> </head> <body> </body> </html>
12 changes: 12 additions & 0 deletions test/fixtures/get-error.src.html
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta charset="UTF-8" />
<title>App</title>
<link rel="stylesheet" href="http://example.com/this_doesnt_exist" />
<script src="http://example.com/this_doesnt_exist"></script>
</head>
<body>
</body>
</html>

0 comments on commit 8af810f

Please sign in to comment.