-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Errors returned by schema.pre('remove') middleware don't display in the Admin UI #536
Comments
Custom deletion hook error messages: issue #536
@morenoh149 @JedWatson I'm still having issues with this, I have a pre-save hook checking for duplicate e-mail adresses. If hit on a duplicate adress i call next with an error object. I'm getting error info in console, but no flash:
The error message don't show up in the admin ui when creating a new user. Am I approaching this the wrong way? |
@larsha That should work. I do it all the time in my projects. Could you post a bare-bones example that reproduces this behaviour? |
Hi @creynders, here's an example of the code: User.schema.pre('save', function(next) {
User.model.findOne({ 'email': this.email }).exec()
.then((user) => {
if (user) {
return next(new Error('E-mail already exists on another user.'));
}
return next();
})
.catch((err) => {
next(new Error(err));
});
}); Here's a screenshot of the admin ui part when no flash error shows after hitting create with an e-mail adress already registered. Although the error shows up in the console as mentioned: |
Is this 0.3? or 0.4? Come to think of it, I don't think I've got any custom validation on |
It's 0.3, that would be helpful, thanks @creynders ! |
I have got the same error, with keystone 0.3.16. The error shows in the console, but the flash message not show. |
I can confirm the bug only happens when creating items, not when editing. Don't know whether it applies to 0.4 too. BTW @larsha this would always fail when trying to save an already existing user, since the query will return the user you're editing. |
Thanks @creynders, some more logic around that one I guess, maybe exclude that user by it's id should solve that problem? _Edit:_ |
fixed in #2566 for v0.4. |
Not working in 4.0.0-beta.5 |
Any update on this @creynders - Not working in 4.0.0-beta.5 |
Any news, guys? |
thanks man for the 'id' part saved life :) |
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:
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:
In the list view it shows the following error in the alert popup:
So it's successfully stopping the 'remove' but not showing the errors I throw.
The text was updated successfully, but these errors were encountered: