Skip to content

Lifecycle Hooks - Errors thrown are not shown in UI #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cmaerz-dn opened this issue May 19, 2025 · 1 comment
Open

Lifecycle Hooks - Errors thrown are not shown in UI #561

cmaerz-dn opened this issue May 19, 2025 · 1 comment
Labels
feature request Community feature request v5 Strapi v5

Comments

@cmaerz-dn
Copy link

I tried to implement custom validation for additionalFields but when i throw an Error on the lifecycle hook the Errors is not shown in strapi UI.
The user cannot save, but I'm not able to display an Error Message.

Background is that I want to validate my custom Fields, cause we need to option that Navigation Items can expire (Seasonal stuff like Easter, Super Bowl and so on)

Note: I tried various other Error Classes, but non was processed.

Code Example:

navigationCommonService.registerLifeCycleHook({
      callback: async (event) => {

        const { expiry_date, start_date } = event.params.data.additionalFields || {};
        
        if (expiry_date && start_date) {
          const expiryDate = new Date(expiry_date);
          const startDate = new Date(start_date);

          if (expiryDate <= startDate) {
            throw new ApplicationError('Validation failed.');
          }
        }

      },
      contentTypeName: "navigation-item",
      hookName: "beforeUpdate",
    });
@cyp3rius
Copy link
Contributor

Hello @cmaerz-dn , the validation is not exposed as part of the codebase yet. After discussions with some users of our plugin during the Strapi Conf we've decided to consider exposing the method for overwriting the zod schemas. Not yet on the backlog, but soon.

@cyp3rius cyp3rius added feature request Community feature request v5 Strapi v5 labels May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Community feature request v5 Strapi v5
Projects
None yet
Development

No branches or pull requests

2 participants