From 50816337aaa9b4653e3831c863495f3c60502523 Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Mon, 18 Nov 2013 14:19:27 -0500 Subject: [PATCH] Send validation error to client if any of the required fields are missing --- controllers/user.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/controllers/user.js b/controllers/user.js index 4aa5ed905c..b83e9252d3 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -33,16 +33,14 @@ exports.postSignup = function(req, res) { password: req.body.password }); - console.log(req.body); - // TODO: add User.schema.path validation - // TODO: check if user already exists in user.save() by catching that error user.save(function(err) { if (err) { + console.log(err); if (err.code === 11000) { return res.send('Duplicate user detected'); - } else { - return res.send('Database validation error'); + } else if (err.name === 'ValidationError') { + return res.send(err.errors); } } req.login(user, function(err) {