From 335c0ac842ed83e1cb5f6d040801610d383b2f39 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Wed, 27 Jan 2016 15:42:37 +0100 Subject: [PATCH] Handle image loading failure (empty body or statusCode other than 200) --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d946171..ec5bd9f 100644 --- a/index.js +++ b/index.js @@ -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); } } }); } @@ -58,4 +61,4 @@ var base64decoder = function (imageBuffer, options, callback) { module.exports = { base64encoder: base64encoder, base64decoder: base64decoder -}; \ No newline at end of file +};