Skip to content

Commit

Permalink
Handle errors when saving a new user
Browse files Browse the repository at this point in the history
return a internal server error and create a user with the result of the saving if everything is ok
  • Loading branch information
gouroujo committed Nov 11, 2015
1 parent 5b6e389 commit 071975d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/server/node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ app.post('/auth/signup', function(req, res) {
email: req.body.email,
password: req.body.password
});
user.save(function() {
res.send({ token: createJWT(user) });
user.save(function(error,result) {
if (error) res.status(500).send({ message: error.message });
res.send({ token: createJWT(result) });
});
});
});
Expand Down

0 comments on commit 071975d

Please sign in to comment.