# Error management when migrating Rules to Actions

**URL:** <https://community.auth0.com/t/error-management-when-migrating-rules-to-actions/136496>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [June 17, 2024, 3:05pm UTC](https://community.auth0.com/t/error-management-when-migrating-rules-to-actions/136496 "2024-06-17T15:05:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![strahinja.ducic](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/strahinja.ducic/32/57889_2.png) [@strahinja.ducic](https://community.auth0.com/u/strahinja.ducic)\
**Post date:** [June 17, 2024, 3:05pm UTC](https://community.auth0.com/t/error-management-when-migrating-rules-to-actions/136496/1 "2024-06-17T15:05:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 17, 2024, 4:27pm UTC](https://community.auth0.com/t/error-management-when-migrating-rules-to-actions/136496/3 "2024-06-17T16:27:57Z")

</div>

Hey there @strahinja.ducic welcome to the community!

> [@strahinja.ducic](#):
>
> 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.

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`:

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

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 1, 2024, 4:28pm UTC](https://community.auth0.com/t/error-management-when-migrating-rules-to-actions/136496/4 "2024-07-01T16:28:36Z")

</div>

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