Send validation error to client if any of the required fields are missing
This commit is contained in:
@ -33,16 +33,14 @@ exports.postSignup = function(req, res) {
|
|||||||
password: req.body.password
|
password: req.body.password
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(req.body);
|
|
||||||
|
|
||||||
// TODO: add User.schema.path validation
|
// TODO: add User.schema.path validation
|
||||||
// TODO: check if user already exists in user.save() by catching that error
|
|
||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
if (err.code === 11000) {
|
if (err.code === 11000) {
|
||||||
return res.send('Duplicate user detected');
|
return res.send('Duplicate user detected');
|
||||||
} else {
|
} else if (err.name === 'ValidationError') {
|
||||||
return res.send('Database validation error');
|
return res.send(err.errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
req.login(user, function(err) {
|
req.login(user, function(err) {
|
||||||
|
Reference in New Issue
Block a user