strapi-plugin-navigation icon indicating copy to clipboard operation
strapi-plugin-navigation copied to clipboard

Lifecycle Hooks - Errors thrown are not shown in UI

Open cmaerz-dn opened this issue 6 months ago • 1 comments

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",
    });

cmaerz-dn avatar May 19 '25 07:05 cmaerz-dn

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 avatar May 19 '25 13:05 cyp3rius

@cmaerz-dn support added in v3.1.0

cyp3rius avatar Jul 18 '25 09:07 cyp3rius