Permalink
Browse files

handle errors better

  • Loading branch information...
1 parent e74b6d0 commit d45be6d872f8fe59380e370d30cce08cb736218d @wadey wadey committed Nov 3, 2011
Showing with 15 additions and 2 deletions.
  1. +8 −1 lib/image.js
  2. BIN public/images/fail.png
  3. +7 −1 routes/index.js
View
@@ -50,7 +50,11 @@ function applyOverlay(image, options, callback) {
var photo = options.face.photos[0]
- options.face.photos[0].tags.forEach(function(face) {
+ if (!photo.tags) {
+ return callback(null, null)
+ }
+
+ photo.tags.forEach(function(face) {
try {
var transform = mapping[options.overlay](face, photo)
} catch (err) {
@@ -94,6 +98,9 @@ exports.mash = function(data, callback){
},
function(err, results) {
if (err) return callback(err)
+
+ if (!results.face.photos[0]) return callback(null, null)
+
var options = {
face: results.face,
overlay: data.overlay
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -11,7 +11,13 @@ exports.img = function(req, res, next) {
}
image.mash(data, function(err, image) {
- if (err) return next(err)
+ if (err) {
+ console.log(err.stack || err)
+ return res.sendfile('public/images/fail.png')
+ }
+ if (!image) {
+ return res.sendfile('public/images/fail.png')
+ }
res.send(image, {'Content-Type': 'image/jpeg'}, 200)
})
};

0 comments on commit d45be6d

Please sign in to comment.