Custom Error Message from throwValidationError Not Displayed in UI

Feature(s) impacted

The issue impacts the error handling feature in Forest Admin, specifically the display of custom error messages in the UI when using throwValidationError in a Before Create/Update hook for a collection.

Observed behavior

When I throw a custom validation error using context.throwValidationError('Test error !!!') in a Before Create or Before Update hook for the any collection, the server correctly returns the error with my custom message in the response:

{
  "errors": [
    {
      "name": "ValidationError",
      "detail": "Test error !!!",
      "status": 400
    }
  ]
}

However, the Forest Admin UI does not display my custom message (“Test error !!!”). Instead, it shows a generic message: “An error occurred when trying to create vertical: Unexpected data sent to the server.”

Here is the relevant code for the Before Create hook:

collection.addHook('Before', 'Create', async (context) => {
    context.throwValidationError('Test error !!!');
});

I have also tried throwing a standard Error with throw new Error('Test error !!!') to format the error response, but the UI still does not display my custom message.

This functionality was working a week ago, and validation messages were displayed correctly.

Expected behavior

I expect the Forest Admin UI to display my custom error message (“Test error !!!”) when I throw it using context.throwValidationError or throw new Error in the Before Create/Before Update hook. The UI should show the message from the detail field of the server response.

Failure Logs

Here are the server(agent) logs when the error is thrown:

ValidationError: Test error !!!
    at InternalHookBeforeCreateContext.throwValidationError (/home/projects/forest-admin-source/node_modules/@forestadmin/datasource-customizer/dist/context/agent-context.js:26:15)

Context

  • Project name: test
  • Team name: test
  • Environment name: development
  • Database type: supabase
  • Recent changes made on your end if any: added additional validation and noticed that the previous ones (which worked well a week ago) are now broken.

And, if you are self-hosting your agent:

  • Agent technology: nodejs
  • Agent (forest package) name & version (from your .lock file): “@forestadmin/agent”: “^1.61.1”,

Hi @ranton and welcome in our community :tada: !

I do reproduce your issue. I will create a bug ticket, it should be fixed today or tomorrow.

Sorry about that :folded_hands:

1 Like

Hi @vince, thanks! Looking forward to some good news!

Hi @ranton,

The fix is live, can you let me know if it works on your side :folded_hands: ?

Thank you!
Everything is working now, the validation messages are displaying correctly! :+1: