Closed
Description
As reported by David Vermeir in the Google Group:
When you try to delete an item but throw an error in a 'remove' hook it doesn't show up in the flashMessages in the detail view, or in the alert box in the list view.
Test case:
/*
* Stop deletion of challenge if already active
* */
Challenge.schema.pre('remove', function(next) {
if(this.status === 1) { return next(new Error("You can't remove a challenge once it's been activated!")); }
keystone.list('UserChallenge').model.findOne({challenge: this._id}).exec(function(err, userChallenge) {
if(userChallenge) { return next(new Error("You can't remove a challenge that's in use by a player!")); }
next();
});
});
Return an error in the next() callback usually works for 'save' hooks but not for 'remove'.
In the detail view it shows the following error in the flash messages section:
There was an error deleting Challenge (logged to console)
In the list view it shows the following error in the alert popup:
There was an error deleting the challenge. ( error: database error)
So it's successfully stopping the 'remove' but not showing the errors I throw.