I am trying to use checkit with a bookshelf, and after adding validation rules, deliberately breaking them, my # catch block promise doesn't seem to catch the error. (I might also not completely understand the use of the catch here)
var validationRules = new Checkit({
email: 'required',
password: 'required'
});
var User = bookshelf.Model.extend({
tableName: 'users',
initialize: function() {
this.on('saving', this.validateSave);
},
validateSave: function() {
validationRules.run(this.attributes);
}
});
User.forge({}).save().then(function(validated) {
console.log('this shouldnt trigger');
}).catch(function(err) {
console.log(e.message);
});
When I create an empty user object, I get the following unhandled stacktrace error, and also seeing how the DB query is built (which may be a separate issue for the bookshelf project and what happens when you connect to the “save” ')
Possibly unhandled Checkit Errors - email: The email is required; password: The password is required
at checkit/checkit.js:105:23
at tryCatch1 (bluebird/js/main/util.js:45:21)
at Promise._callHandler (bluebird/js/main/promise.js:597:13)
at Promise._settlePromiseFromHandler (bluebird/js/main/promise.js:607:18)
at Promise._settlePromiseAt (checkit/node_modules/bluebird/js/main/promise.js:769:18)
at Promise._settlePromises (checkit/node_modules/bluebird/js/main/promise.js:884:14)
at Async._drainQueue (checkit/node_modules/bluebird/js/main/async.js:98:12)
at Async._drainQueues (checkit/node_modules/bluebird/js/main/async.js:103:10)
at Async.drainQueues (checkit/node_modules/bluebird/js/main/async.js:37:14)
at process._tickCallback (node.js:415:13)
{ __cid: '__cid1',
method: 'insert',
options: undefined,
bindings: [],
sql: 'insert into `users` () values ()' }
ER_NO_DEFAULT_FOR_FIELD: Field 'email' doesn't have a default value
I have 2 questions:
debug: true knex, stacktrace ER_NO_DEFAULT_FOR_FIELD, , SQL-. , Checkit , SQL ?- #catch? , . (,
e.message #catch MySQL, Checkit). , ?
bookshelf.js docs (http://bookshelfjs.org/) Checkit (https://github.com/tgriesser/checkit)