Skip to content

Commit

Permalink
better error handling on user registration
Browse files Browse the repository at this point in the history
  • Loading branch information
evaletolab committed Sep 2, 2014
1 parent b0652a7 commit ca4b532
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 12 additions & 2 deletions app/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ var tokenSession=function (req, res, next) {

// don't use logger for test env
if (process.env.NODE_ENV !== 'test') {
app.use(express.logger(':remote-addr - :date - :method :url :status :res[content-length] - :response-time ms'))
// express.logger.token('msg', function(req, res){
// if(res.status>=400){
// console.log(res.text)
// return res.text
// }
// return ''
// })

app.use(express.logger(':remote-addr - :date - :method :url :status :msg - :referrer - :response-time ms'))
}


Expand Down Expand Up @@ -197,7 +205,8 @@ var tokenSession=function (req, res, next) {
// || (~err.message.indexOf('Cast to ObjectId failed')))) {
// return next()
// }



//send emails if you want
if(process.env.NODE_ENV==='production'){
var msg=(err.stack)?err.stack:JSON.stringify(err,null,2);
Expand All @@ -207,6 +216,7 @@ var tokenSession=function (req, res, next) {
});
}


if (typeof err==='string'){
return res.send(400,err);
}
Expand Down
8 changes: 7 additions & 1 deletion controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,24 @@ exports.register_post= function(req, res) {
check(req.body.lastname,"Le format de prénom est invalide").len(3, 64);
check(req.body.password,"Le passowrd est invalide").len(3, 64);
}catch(err){
console.log("[register] ", err.message)
return res.send(400, err.message);
}

db.model('Users')
.register(req.param('email'),req.param('firstname'),req.param('lastname'),req.param('password'),req.param('confirm'),
function(err,user){
if(err&&err.code==11000){
console.log("[register] ", "Cet adresse email est déjà utilisée")
return res.send(400,"Cet adresse email est déjà utilisée");
}else
if (err){
return res.send(400,errorHelper(err));
}

if (!user){
return res.send(400,"Unknow error on registration");
console.log("[register] Ooooppss!!")
return res.send(400,"Erreur inconnue lors de la création du compte");
}
//
// redirect for non ajax register
Expand Down

0 comments on commit ca4b532

Please sign in to comment.