Can't set the error code in an action

Hi everyone,
In the migration process from the rules to the new actions, I’ve found out that I cannot specify the error thrown to the user but I can only set the message. The two pieces of code are the following:

exports.onExecutePostLogin = async (event, api) => {
  if (!event.user.email_verified) {
      api.access.deny("Please verify your email before logging in.");


function (user, context, callback) {
  if (!user.email_verified) {
    return callback(new UnauthorizedError('Please verify your email before logging in.'));
  } else {
    return callback(null, user, context);

The result of the action is:

  "error": "access_denied",
  "error_description": "Please verify your email before logging in."

The result of the rule is:

  "error": "unauthorized",
  "error_description": "Please verify your email before logging in."

My frontend application relies on the error field to show the corresponding error in various other languages and now I will need to update the error map to accept the “access_denied” string as a valid error and not show the default error.

We don’t have the API to change that “error” field, is this by design or it will be implemented in the future? Is there a plan to support this or for now we either need to deploy our FE or use the old rule as long as actions will support the legacy rules?

Hi @mattia.pettenuzzo ,

I’m afraid I could not find any evidence of this being currently worked on or planned. I would recommend raising this as a feedback request here: Feedback

Until such a thing were implemented, I would recommend using the error description field to generate your application’s own error message, you could pass your own custom error codes for example or just look for the string, and have your application render the appropriate message based on the description, in the user’s own language.

1 Like

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