Error management when migrating Rules to Actions

I need your assistance with our migration from Rules to Actions.
We are encountering a specific issue regarding how to handle errors returned from the newly created actions.
Previously, in Rules, we managed errors by throwing them as follows: return new Error(some_message), return callback (new UnauthorizedError(some_message)).
How can we return all those error messages in Actions?
Is the only possible way to achieve this by using api.access.deny(some_message)?
This question pertains to the post-login flow.
Is it possible to return an UnauthorizedError within Actions in any way?
Please respond as the deadline for the migration is approaching. Thank you in advance.

Hey there @strahinja.ducic welcome to the community!

That’s correct, you’ll want to utilize api.access.deny(reason) in Actions - The error code will always be access_denied with the error_description as the provided reason. An example post-login Action checking for a verified email and a blocked property in event.user.user_metadata:

exports.onExecutePostLogin = async (event, api) => {
  if (!event.user.email_verified) {
    api.access.deny('Email not verified.');
  if (event.user.user_metadata && event.user.user_metadata.blocked) {
    api.access.deny('User is blocked.');
  // other logic

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.