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

**URL:** <https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406>\
**Category:** Help me!\
**Created:** [August 22, 2024, 8:28am UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406 "2024-08-22T08:28:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matteo](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/matteo/32/75_2.png) [@Matteo](https://community.forestadmin.com/u/Matteo)\
**Post date:** [August 22, 2024, 8:28am UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406/1 "2024-08-22T08:28:34Z")

</div>

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](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/result-builder)), 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 (11)](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/b/bd8570b092ff30ed6bb8eea0dfcbec1a64b82ed9.png)

![image (12)](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/50c0474003b7841d540ce2663a74acb8ec28c8db.png)

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

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

```

and from `package.json`:

```javascript
"sequelize": "^6.28.0"

```

cc @julien.jolles

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [August 22, 2024, 8:56am UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406/2 "2024-08-22T08:56:25Z")

</div>

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.

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

```

You can find an example in our [migrations steps here](https://docs.forestadmin.com/developer-guide-agents-nodejs/getting-started/migrating/steps/code-transformations/route-overrides#add-custom-permissions). If you are not aware, we created [a guide](https://docs.forestadmin.com/developer-guide-agents-nodejs/getting-started/migrating) to help users migrate from the old agent to the new @forestadmin/agent since it can be arduous.

Best regards,

---

<div class="post-metadata">

**Author:** ![Matteo](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/matteo/32/75_2.png) [@Matteo](https://community.forestadmin.com/u/Matteo)\
**Post date:** [August 22, 2024, 10:08am UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406/3 "2024-08-22T10:08:07Z")

</div>

Thank you @anon7284711

…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 😅

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

> **[Collection override | Node.js Developer Guide](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/hooks/collection-override#create-over-api)**

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

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [August 22, 2024, 10:25am UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406/4 "2024-08-22T10:25:20Z")

</div>

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

```javascript
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](https://docs.forestadmin.com/developer-guide-agents-nodejs/getting-started/install/create-your-agent#customizeerrormessage-function-defaults-to-null) for the agent to use.

---

<div class="post-metadata">

**Author:** ![Matteo](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/matteo/32/75_2.png) [@Matteo](https://community.forestadmin.com/u/Matteo)\
**Post date:** [August 22, 2024, 2:05pm UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406/5 "2024-08-22T14:05:07Z")

</div>

> [@anon7284711](#):
>
> 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.

Ok, thank you for doublechecking this 🙏

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

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [August 22, 2024, 2:14pm UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406/6 "2024-08-22T14:14:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matteo](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/matteo/32/75_2.png) [@Matteo](https://community.forestadmin.com/u/Matteo)\
**Post date:** [August 23, 2024, 8:18am UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406/7 "2024-08-23T08:18:54Z")

</div>

Ok thank you, I see.

So we have some alternative ways to achieve the result 👍

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

Thank you,  
Matteo

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [August 23, 2024, 10:31am UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-routes-overrides-dont-allow-custom-feedback/7406/8 "2024-08-23T10:31:53Z")

</div>

No need to wait! 🙂

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

Best regards,
