Auth0 Rule Error

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);
    }
  }

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

Hi @shubham.kohli :wave:

Welcome to the community :sunglasses:

:thinking: 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 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 :sunglasses:

1 Like

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