From a1fdd6f43395d2a208100cc07a2769a1b684bedf Mon Sep 17 00:00:00 2001 From: Stephen Whitmore Date: Thu, 28 Dec 2017 11:41:15 -0800 Subject: fix: fail gracefully on jpeg rotation exception --- lib/serve.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'lib/serve.js') diff --git a/lib/serve.js b/lib/serve.js index 76b3a8c..0c1ede8 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -1210,15 +1210,20 @@ Serve.prototype.image = function (path) { if (err) return heresTheData(err) buffer = Buffer.concat(buffer) - jpeg.rotate(buffer, {}, function (err, rotatedBuffer, orientation) { - if (!err) buffer = rotatedBuffer + try { + jpeg.rotate(buffer, {}, function (err, rotatedBuffer, orientation) { + if (!err) buffer = rotatedBuffer - heresTheData(null, buffer) - pull( - pull.once(buffer), - self.respondSink() - ) - }) + heresTheData(null, buffer) + pull( + pull.once(buffer), + self.respondSink() + ) + }) + } catch (err) { + console.trace(err) + self.respond(500, err.message || err) + } } done(function (err, data, type) { -- cgit v1.2.3