How can i display custom validation error to admin user

  1. i am creating a blog with an external url link to be validated with custom regex.
  2. i am able to validate and generate the error but un ale to link to custom error to admin panel

module.exports = {
lifecycles:
{
async beforeCreate(data)
{
let message =" URL should match http:// format"
let regex = /[(http(s)?)://(www.)?a-zA-Z0-9@:%.+~#=]{2,256}.[a-z]{2,6}\b([-a-zA-Z0-9@:%+.~#?&//=]*)/
if(!regex.test(data.external_link))

        {
               
                throw new Error(message)
                
        }
     
       
    }
}

};

**i mean this error message to admin **

Im also having same issue looking for a solution to display a error message to the Admin who creating a record
My case is checking the duplication entry with few combination while saving a record. was able to achieve the check but unable to throw proper error to the admin

tried few option, but this stops the execution in local.
if(false) {
throw strapi.errors.badRequest(‘Duplicate Data’);
}

looking for solution and my version is 3.1.4

try this ;
if(false) {
throw strapi.errors.badRequest(‘Duplicate Data’, {
field: [‘Duplicate Data’],
});
}

1 Like

Awesome!!. it works like charm and didn’t break my local execution too. Thank you very much for prompt response

In case someone is looking for the solution in V4: Throw Error message in lifecycle hook doesnt change the error message display in the UI - #8 by taka