prevent double res.send/json if error occurs in profile image upload

This commit is contained in:
Baris Soner Usakli
2014-01-08 02:59:14 -05:00
parent 2d384a68d2
commit 0d26b21a2c

View File

@@ -176,23 +176,25 @@ var fs = require('fs'),
user.setUserField(uid, 'picture', imageUrl); user.setUserField(uid, 'picture', imageUrl);
if (convertToPNG && extension !== '.png') { if (convertToPNG && extension !== '.png') {
im.convert([uploadPath, 'png:-'], im.convert([uploadPath, 'png:-'], function(err, stdout) {
function(err, stdout){ if (err) {
if (err) { winston.err(err);
winston.err(err); res.send({
res.send({ error: 'Unable to convert image to PNG.'
error: 'Unable to convert image to PNG.' });
}); return;
return; }
}
fs.writeFileSync(uploadPath, stdout, 'binary'); fs.writeFileSync(uploadPath, stdout, 'binary');
res.json({
path: imageUrl
}); });
});
} else {
res.json({
path: imageUrl
});
} }
res.json({
path: imageUrl
});
} }
if(extension === '.gif') { if(extension === '.gif') {