Errors returned by schema.pre('remove') middleware don't display in the Admin UI
See original GitHub issueAs 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.
Issue Analytics
- State:
- Created 9 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
node.js - Mongoose model query(findById) error in hooks(pre ...
I found out a trick in another topic, which is to replace inside the middleware Protocol.findById() by mongoose.model('Protocol').findById() , ...
Read more >Mongoose v6.8.1: Middleware
There are several ways to report an error in middleware: schema. pre('save', function(next) { const err = new Error('something went wrong'); // If...
Read more >pre.remove middleware of objects in array are never called ...
When removing FileSpace, pre remove middleware is never call (but pre ... ... 'use strict'; var mongoose = require('mongoose'), Schema ...
Read more >API Reference: ApolloServer - Apollo GraphQL Docs
An executable GraphQL schema. Under the hood, Apollo Server automatically generates this field from typeDefs and resolvers . This field is helpful if:...
Read more >Get started with Swashbuckle and ASP.NET Core
NET Core web API project to integrate the Swagger UI. ... what's returned—specifically response types and error codes (if not standard).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any news, guys?
Not working in 4.0.0-beta.5