From a14810a2e0e362141b16089b69d8b41fd032407a Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 18 Sep 2015 09:42:09 -0400 Subject: [PATCH] wrap lwip.open in try catch, it throws on unknow types, closes #3632 --- src/image.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/image.js b/src/image.js index d35040ff9d..73a73fc0aa 100644 --- a/src/image.js +++ b/src/image.js @@ -17,7 +17,7 @@ image.resizeImage = function(path, extension, width, height, callback) { callback(err); }); } else { - lwip.open(path, function(err, image) { + tryOpen(path, function(err, image) { if (err) { return callback(err); } @@ -41,7 +41,7 @@ image.normalise = function(path, extension, callback) { callback(err); }); } else { - lwip.open(path, function(err, image) { + tryOpen(path, function(err, image) { if (err) { return callback(err); } @@ -50,6 +50,14 @@ image.normalise = function(path, extension, callback) { } }; +function tryOpen(path, callback) { + try { + lwip.open(path, callback); + } catch (err) { + callback(err); + } +} + image.convertImageToBase64 = function(path, callback) { fs.readFile(path, function(err, data) { callback(err, data ? data.toString('base64') : null);