Node-sdk; Management Client; FetchError: The request failed and the interceptors did not return an alternative response

There are some methods from the Management Client failing and returning this error:

FetchError: The request failed and the interceptors did not return an alternative response
    at BaseAPI.fetch (/.../api/node_modules/auth0/dist/cjs/lib/runtime.js:84:27)
    at async OAuth.request (/.../api/node_modules/auth0/dist/cjs/lib/runtime.js:115:26)
    at async grant (/.../api/node_modules/auth0/dist/cjs/auth/base-auth-api.js:84:22) {
  cause: TypeError: Cannot construct a Request with a Request object that has already been used.
      at node:internal/deps/undici/undici:12618:11
      at propagateAslWrapper (/.../api/node_modules/async-listener/index.js:504:23)
      at /.../api/node_modules/async-listener/glue.js:188:31
      at /.../api/node_modules/async-listener/index.js:541:70
      at /.../api/node_modules/async-listener/glue.js:188:31
}

Here is a snippet that is throwing the error:

export const getPermissionsManagementConfigs = async (clientId: number) => {
    try {
        const { managementConfigs } = (await configs({
            clientId,
        })) as IAuth0Config;

        console.log('managementConfigs: ', managementConfigs);

        // const { domain, audience, clientSecret } = managementConfigs;

        const client = new ManagementClient({
            domain: '****,
            clientId: '****',
            clientSecret:
                '****',
        });

        console.log('client: ', client.roles);

        const { data: roles } = await client.roles.getAll().catch(err => {
            console.log('error getting roles: ', err);
            throw new Error('ERROR GETTING ROLES');
        });

        return { client, roles, managementConfigs };
    } catch (err) {
        const error = processError(err);
        throw new Error(
            `ERROR GETTING PERMISSIONS MANAGEMENT CONFIGS: ${error}`,
        );
    }
};

***IMPORTANT ***
The domain, clientId, and clientSecret have been triple checked for correctness.

The error seems to indicated that the sdk library is trying reuse a Request object.

Are there any solutions to this?

1 Like

Hey, did you find a solution to this yet? I’m experiencing this issue as well.

Yes! Our problem was another package actually, dd-trace. They pushed a minor update 5.10.xx to 5.11.xx. In it, they introduced a bug that was improperly handling the global.fetch Request and allowing it to be reused. We rolled back our version and the problem is resolved.

Thanks for the helpful tip! Ran into the same problem, and FYI dd-trace v5.12.0 resolves the issue for us.

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