Skip to content

Commit

Permalink
Handle image loading failure (empty body or statusCode other than 200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paula Stachova committed Jan 27, 2016
1 parent 0b6ba64 commit 335c0ac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ var base64encoder = function (url, options, callback) {

if (body && res.statusCode === 200) {
return encoder(body, options);
} else {
if (!body) { return callback('Image loading error - empty body'); }
else { return callback('Image loading error - ' + res.statusCode); }
}
});
}
Expand All @@ -58,4 +61,4 @@ var base64decoder = function (imageBuffer, options, callback) {
module.exports = {
base64encoder: base64encoder,
base64decoder: base64decoder
};
};

0 comments on commit 335c0ac

Please sign in to comment.