Throw Error message in lifecycle hook doesnt change the error message display in the UI

I was able to get an error to appear by adding a global middleware since Strapi v4 allows error handling with the ctx object. Error handling - Strapi Developer Docs

module.exports = (config, { strapi }) => {
  // Add your own logic here.
  return async (ctx, next) => {
    
    strapi.log.info('In page-adjuster middleware.');
    
    // check that the page content is being changed
    if ( (ctx.request.method === 'PUT' || ctx.request.method === 'POST') &&
      ctx.request.url.includes('/content-manager/collection-types/api::page.page')) {
      // check if the slug is restrictive
      if (ctx.request.body.slug === 'test') {
        strapi.log.info('restrictive slug');
        return ctx.badRequest('Restricted slug: Choose a different slug', { slug: ctx.request.body.slug })
      }
    }
    await next();
  };
};