integrating validation module in node.js
I am using the following node module for validation:
https://github.com/chriso/node-validator
Now, suppose I want to check on an user input like this
check('abc').isInt(); I noticed that it basically throws an error!
I am pretty new with node.js but it seems to me that having to use
try{}catch(e){} blocks every time I need to check on a user input is a bit
on an overkill.
wouldn't it make more sense to have something like
if (check('abc').isInt()) {
// Do things here
next(null, stuff_I_want_to_return)
} else next(error);
instead of
try{
check('abc').isInt()
next(null, stuff_I_want_to_return)
} catch(e) { next(e); }
?? I have no idea, please clarify on what is the best approach to have in
this case. Thanks in advance.
No comments:
Post a Comment