Migration to `@forestadmin/agent` - Routes overrides don't allow custom feedback

We’re migrating from forest-express-sequelize to @forestadmin/agent.

Routes overrides don’t allow custom feedback (nor positive nor negative).

Smart actions let you do so using a ResultBuilder (see docs), but for the overrideCreate, overrideUpdate and overrideDelete it’s not given.

e.g. Collection with a delete override. The custom error message is printed in the console, but not shown in the frontend.

image (12)

Here is the “meta” section of the forest admin schema file:

  {
    "liana": "forest-nodejs-agent",
    "liana_version": "1.41.7",
    "liana_features": null,
    "stack": {"engine": "nodejs", "engine_version": "20.11.1"}
  }

and from package.json:

"sequelize": "^6.28.0"

cc @julien.jolles

Hello @Matteo,

You can so by using the context object given to your override#### function, it contains three types of error functions you can use, each expecting your custom message.

  throwValidationError(message: string)
  throwForbiddenError(message: string)
  throwError(message: string)

You can find an example in our migrations steps here. If you are not aware, we created a guide to help users migrate from the old agent to the new @forestadmin/agent since it can be arduous.

Best regards,

1 Like

Thank you @dogan.ay

…But we’re using overrides, not hooks. And the functions you listed come from hooks and they are not available in overrides.

So the solution can be one of the following:

  • you export these functions in the overrides as well or
  • you export the result builder helper in the override functions (as you already do in the execute function of the action)

We don’t use hooks because we’re migrating from your express-sequelize lib and we have a lot of existing express middleware chains.
So we built some adapters to use our existing code. And we have some very complex functions in our middlewares and rewriting these is absolutely not an option :sweat_smile:

In your docs you say that we can use the override function also to interact with external APIs.

If we do this, how can we tell the outcome to the user if we can’t bring an error/success message in the forest UI???

Thank you.
Matteo

the functions you listed come from hooks and they are not available in overrides.

I was expecting them to be available on any context, I don’t see why it wouldn’t be the case. I’ll take about this with the team.

There are 2 other ways to handle error messages with the new agent, you could simply throw the errors exported by @forestadmin/datasource-toolkit (a sub dependency of the agent, so not required to be define in your package.json)

Like so:

const { UnprocessableError } = require("@forestadmin/datasource-toolkit");
...
  (context) => {
    throw new UnprocessableError("This is a test");

Or you could use your own error classes and then define an error translator for the agent to use.

Ok, thank you for doublechecking this :pray:

And thank you for proposing a workaround.
But with these workarounds we’re not able to set positive messages, thou.

Let me me know, please.

Thank you,
Matteo

Indeed, you cannot customize the success response on routes, as the frontend expects the resulting record(s) after the operation.

Ok thank you, I see.

So we have some alternative ways to achieve the result :+1:

I was expecting them to be available on any context, I don’t see why it wouldn’t be the case. I’ll take about this with the team.

Let us know if we need to go on with these workarounds or if it’s better to wait for this check on your side :pray:

Thank you,
Matteo

No need to wait! :slight_smile:

The functions are now available in most context, you can try it out now with @forestadmin/agent v1.41.10

Best regards,

2 Likes