[v4] How to throw an error in a lifecycle hook?

I got to do it doing this:

const { ForbiddenError } = require("@strapi/utils").errors;

...

if (!authorized) {
  throw new ForbiddenError(errorMessage);
}

You can check the errors available in @strapi/utils/lib/errors.js

9 Likes