Skip to content

Commit

Permalink
Improved error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Aug 2, 2013
1 parent 0b9bb70 commit 7973ace
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/processImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ module.exports = function (options) {

function sendErrorResponse(err) {
if (!hasEnded) {
res.statusCode = 500;
res.end();
hasEnded = true;
if (seenData) {
res.statusCode = 500;
res.end();
} else {
res.unhijack(function () {
next(err);
});
}
}
}

Expand All @@ -67,7 +73,9 @@ module.exports = function (options) {
// filters[filters.length - 1].pipe(res);
filters[filters.length - 1].on('data', function (chunk) {
seenData = true;
res.write(chunk);
if (!hasEnded) {
res.write(chunk);
}
}).on('end', function () {
if (!hasEnded) {
if (seenData) {
Expand Down

0 comments on commit 7973ace

Please sign in to comment.