Throwing error in lifecycle hook doesn't stop script from executing

Hello @sunnyson, could you help me? I followed your instructions and despite showing a 422 error, the post is still published. Here is the code:

async beforeCreate(params, data) {
      const post = await strapi.query('post').find({ id: params.id });
      if (
        post[0].published_at &&
        (!post[0].subcategories.length || !post[0].categories.length)
      ) {
        throw new Error('Category or subcategory is missing');
      }
    }