-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add more info to validation errors #56
Comments
Hi, Can you give me an example that doesn't work as expected? I'm sure there are some cases that don't get handled properly. Here is an example that does show the error: 'use strict';
var connect = require('camo').connect;
var Document = require('camo').Document;
class Person extends Document {
constructor () {
super();
this.fullName = Number;
}
}
connect('nedb://memory').then(function(db) {
var billy = Person.create({
fullName: 'Billy Bob'
});
billy.save().then(function(data) {
console.log('Saved people...');
}).catch(function(err) {
console.log('Error:', err.message);
});
}); This outputs:
Thanks! |
I had the following class User extends Document {
constructor() {
super();
this.schema({
name: {
type: String,
required: true
},
sex: {
type: String,
required: true
}
updated_at: {
type: Date,
},
created_at: {
type: Date,
}
});
}
}
User.create({ name: '' }).save().catch(function (err) { res.send(err) }); And you're right. it works when you send it like you did Is there a way to run the whole validation and get everything wrong with the passed params? Meaning in the example I've showed the error should be a bit more complex. |
Yes, that would be a nice improvement for the validator. Right now Camo just throws the first error it finds. I'll add this to the todo list. Thanks! |
Hi,
is there a way to get the reasons why validation did not pass? It would be nice to send some response why I did not allow to create/update the document?
I've glanced at the code but as far as I could tell all the validation errors are suppressed under the promise. No reasons are passed to the
catch
function when I do (for example)user.save().catch(function (err) { console.log(err) })
.the
err
object is just an empty object.Have I missed something?
The text was updated successfully, but these errors were encountered: