question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors returned by schema.pre('remove') middleware don't display in the Admin UI

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
langovoicommented, Aug 19, 2017

Any news, guys?

1reaction
VinayaSathyanarayanacommented, Jun 10, 2017

Not working in 4.0.0-beta.5

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found