# Auth0 Rule Error

**URL:** <https://community.auth0.com/t/auth0-rule-error/103858>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [March 31, 2023, 1:51pm UTC](https://community.auth0.com/t/auth0-rule-error/103858 "2023-03-31T13:51:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shubham.kohli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shubham.kohli/32/45086_2.png) [@shubham.kohli](https://community.auth0.com/u/shubham.kohli)\
**Post date:** [March 31, 2023, 1:51pm UTC](https://community.auth0.com/t/auth0-rule-error/103858/1 "2023-03-31T13:51:56Z")

</div>

Im getting below error for a rule ::

6:56:47 PM:

{ “code”: 500, “error”: “Script generated an unhandled asynchronous exception.”, “details”: “TypeError: Cannot read properties of undefined (reading ‘roles’)”, “name”: “TypeError”, “message”: “Cannot read properties of undefined (reading ‘roles’)”, “stack”: “TypeError: Cannot read properties of undefined (reading ‘roles’)\n at \_id (/data/io/node16/1431a683-fe24-4291-b240-a26e9ea6abfa/webtask.js:138:84)\n at fn (/data/sandbox/node16/node\_modules/@a0/auth0-authz-rules-api/async.js:36:22)\n at /data/sandbox/node16/node\_modules/@a0/auth0-authz-rules-api/async.js:73:20\n at processTicksAndRejections (node:internal/process/task\_queues:78:11)” }

6:56:47 PM:

finished webtask request

6:56:47 PM:

Code generated an uncaught exception: TypeError: Cannot read properties of undefined (reading ‘roles’) at \_id (/data/io/node16/1431a683-fe24-4291-b240-a26e9ea6abfa/webtask.js:138:84) at fn (/data/sandbox/node16/node\_modules/@a0/auth0-authz-rules-api/async.js:36:22) at /data/sandbox/node16/node\_modules/@a0/auth0-authz-rules-api/async.js:73:20 at processTicksAndRejections (node:internal/process/task\_queues:78:11)

It Seems below function in my rule is giving error

```
 request(reqOptions, function handleResponse(err, response, body) {
    if (err) {
      reject(err);
    } else if (response.statusCode < 200 || response.statusCode >= 300) {
      console.error(LOG_TAG, 'API call failed: ', body);
      reject(new Error(body));
    } else {
      resolve(response.body);
    }
  }

```

---

<div class="post-metadata">

**Author:** ![shubham.kohli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shubham.kohli/32/45086_2.png) [@shubham.kohli](https://community.auth0.com/u/shubham.kohli)\
**Post date:** [March 31, 2023, 1:52pm UTC](https://community.auth0.com/t/auth0-rule-error/103858/2 "2023-03-31T13:52:27Z")

</div>

@konrad.sopala Can you Assist here . I need to fix on urgent basis

---

<div class="post-metadata">

**Author:** ![peter.fernandez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/peter.fernandez/32/45477_2.png) [@peter.fernandez](https://community.auth0.com/u/peter.fernandez)\
**Post date:** [March 31, 2023, 2:15pm UTC](https://community.auth0.com/t/auth0-rule-error/103858/3 "2023-03-31T14:15:46Z")

</div>

Hi @shubham.kohli 👋

Welcome to the community 🕶

🤔 So, a couple of things:

> { “code”: 500, “error”: “Script generated an unhandled asynchronous exception.”, “details”: “TypeError: Cannot read properties of undefined (reading ‘roles’)”, “name”: “TypeError”, “message”: “Cannot read properties of undefined (reading ‘roles’)”, “stack”: “TypeError: Cannot read properties of undefined (reading ‘roles’)\n at \_id (/data/io/node16/1431a683-fe24-4291-b240-a26e9ea6abfa/webtask.js:138:84)\n at fn (/data/sandbox/node16/node\_modules/@a0/auth0-authz-rules-api/async.js:36:22)\n at /data/sandbox/node16/node\_modules/@a0/auth0-authz-rules-api/async.js:73:20\n at processTicksAndRejections (node:internal/process/task\_queues:78:11)” }

Suggests that the error is occurring when trying to read `roles` from a null object. Perhaps check the parts of your code where you make `.roles` reference(s) and ensure the object you are reading from is not null in each case.

Also, the way to exit from a Rule is via use of the supplied `callback` function: `callback` should always be called, and it can also be used to generate an error condition back to the client if necessary (see [here](https://auth0.com/docs/customize/rules/raise-errors-from-rules) for more information). Exiting via `resolve` or `reject` will typically cause the Rule pipeline to stall with, or without, generating an exception. Likewise failing to execute `callback` or throwing an unhandled exception will cause the Rule pipeline to stall too.

Hope this helps 🕶

---

<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:** [April 17, 2023, 3:05pm UTC](https://community.auth0.com/t/auth0-rule-error/103858/4 "2023-04-17T15:05:44Z")

</div>

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