Display a red pop up on error (routes)

Hey there :slight_smile:

Thanks for your feedbacks but… I did find a bug :slight_smile: Based on your answer, I don’t know how/why, but I saw the light.

I let you test on your end, but I will provided you a model and 2 examples:

Item.ts

// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
import {Document, model, Schema, Types} from 'mongoose';
import {INote, schema as note} from "./note";

export interface IItem extends Document {
    notes: [INote],
    title: string,
}

// This section contains the properties of your model, mapped to your collection's properties.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const schema = new Schema({
    'notes': [note],
    'title': String
}, {
    timestamps: false,
});

export default model<IItem>('items', schema, 'Items');

Of course, this model has a nested notes array, there is the definition:

Note.ts

import {Document, model, Schema} from 'mongoose';

export interface INote extends Document {
    name: string,
    content: string,
}

// This section contains the properties of your model, mapped to your collection's properties.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
export const schema = new Schema({
    "name": String,
    "content": String,
}, {
    timestamps: false,
    _id: false
});

export default model<INote>('notes', schema)

Now that you have the model definition, I let you create one sample :slight_smile: Let say you create an Item “Test” that has a note with:

  • name: Foo
  • content: Bar

Now that you have everything setup, let’s create the “inconsistent” behavior (if I may call it like that).

BUG

Lets get to your routes/ directory and override the router.put(...) (so the update) section of your items:

// Update an Item
router.put('/items/:recordId', permissionMiddlewareCreator.update(), (request, response, next) => {
    // Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#update-a-record
    throw new Error("Hello there, let's throw an error!")
});

If you now update your previously created record’s title, you will see that red popup, no matter why. You can also use response.status(400).send("Hello there, let's throw an error!") and the result will quite be the same, this I agree with you.

However… now lets try to update our “notes” array :slight_smile:

If you update the existing “foo” note we have, it should run smoothly (note that I don’t get why I don’t get the error as it is an update…)

If you create a new note tho… that’s another story :sweat_smile: You do get the error displayed in the console, but nothing happens on the UI of ForestAdmin :confused: I should see the popup but I don’t see it

That’s kind of sad because, maybe I am missing something, which is a very possible option, either this part of forest admin is not very well done… I am saying so because, in this same section of the forest admin UI, I had this issue: Unable to update the layout for sub document definitions (mongodb) (related to another context, but to the same forest admin UI section/part)

However, thanks for your help/time, we really appreciate! I’ve been testing a couple of BackOffice solution but your is really good, keep moving forward!

Max