Displaying custom error message in Admin UI in Strapi 4.8.x

Hope it hepls someone)

  module.exports = {
    beforeCreate: async (event) => {
      console.log(event);

      const ctx = strapi.requestContext.get();

      ctx.throw(400, {
        details: {
          errors: [
            {
              path: ["slug"],
              message: "This attribute must be unique",
              name: "ValidationError",
            },
          ],
        },
        message: "This attribute must be unique",
        name: "ValidationError"
      });
      return ctx;
    },
    beforeUpdate: async (event) => {

    },
  };

@jangxx @Tirth_Work @0x273464

3 Likes