Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define custom message for validators #1575

Closed
newmanw opened this issue Jul 10, 2013 · 1 comment
Closed

Define custom message for validators #1575

newmanw opened this issue Jul 10, 2013 · 1 comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature

Comments

@newmanw
Copy link

newmanw commented Jul 10, 2013

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");

@aheckmann
Copy link
Collaborator

duplicate of #747 which just landed on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

No branches or pull requests

2 participants