You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently you can only define a custom type for validators. This makes it extremely cumbersome to try and generate an error message that is suitable to return to a client. I.E.
User.schema.path('username').validate(function(value, done) {
User.findOne({username: value}, function(err, user) {
if (err) return done(false);
if (user) return done(false);
done(true);
});
}, "exists");
I have to parse out the error msg:
for (error in err.errors) {
msg += "Error creating/updating user: " + error.path + " " + error.type;
}
Would be nice to add a custom message to validator.
User.schema.path('username').validate(function(value, done) {
User.findOne({username: value}, function(err, user) {
if (err) return done(false);
if (user) return done(false);
done(true);
});
}, "exists", "user name already exists");
The text was updated successfully, but these errors were encountered:
Currently you can only define a custom type for validators. This makes it extremely cumbersome to try and generate an error message that is suitable to return to a client. I.E.
User.schema.path('username').validate(function(value, done) {
User.findOne({username: value}, function(err, user) {
if (err) return done(false);
if (user) return done(false);
});
}, "exists");
I have to parse out the error msg:
for (error in err.errors) {
msg += "Error creating/updating user: " + error.path + " " + error.type;
}
Would be nice to add a custom message to validator.
User.schema.path('username').validate(function(value, done) {
User.findOne({username: value}, function(err, user) {
if (err) return done(false);
if (user) return done(false);
});
}, "exists", "user name already exists");
The text was updated successfully, but these errors were encountered: