Solution for Error "The Request Failed and the Interceptors did not Return an Alternative Response"

Overview

When using the node-auth0 ManagementClient to make requests to the Management API, initializing the SDK with both methods (Client ID and Client Secret, and with Access Token), the following error is received:
FetchError: The request failed and the interceptors did not return an alternative response

The full error log is:

FetchError: The request failed and the interceptors did not return an alternative response
    at BaseAPI.fetch (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:84:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async OAuth.request (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:115:26)
    ... 4 lines matching cause stack trace ...
    at async ClientsManager.request (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:115:26)
    at async ClientsManager.getAll (<REDACTED>/node_modules/auth0/dist/cjs/management/__generated/managers/clients-manager.js:97:26)
    at async runLookup (<REDACTED>/app.js:29:17) {
  cause: TypeError: fetch failed
      at Object.fetch (node:internal/deps/undici/undici:11118:11)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async BaseAPI.fetchWithTimeout (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:34:24)
      at async BaseAPI.fetch (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:66:27)
      at async OAuth.request (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:115:26)
      at async grant (<REDACTED>/node_modules/auth0/dist/cjs/auth/base-auth-api.js:84:22)
      at async TokenProvider.getAccessToken (<REDACTED>/node_modules/auth0/dist/cjs/management/token-provider.js:20:85)
      at async TokenProviderMiddleware.pre (<REDACTED>/node_modules/auth0/dist/cjs/management/token-provider-middleware.js:26:23)
      at async BaseAPI.fetch (/<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:52:26)
      at async ClientsManager.request (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:115:26) {
    cause: Error: getaddrinfo ENOTFOUND https
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {
      errno: -3008,
      code: 'ENOTFOUND',
      syscall: 'getaddrinfo',
      hostname: 'https'
    }
  }
}

Cause

The error shared indicates the error happens at the HTTP layer, inside fetch, which is a native Node module, not part of the Auth0 Node.js Management SDK:

cause: Error: getaddrinfo ENOTFOUND https

or

cause: Error: getaddrinfo ENOTFOUND undefined

Solution

Please make sure that when initializing the ManagementClient from the node-auth0 library, the domain is set correctly, i.e., it is not undefined, and the protocol is not added in front of the domain. Always follow the instructions from the documentation here.

  • Initialize the client class with a client ID, client secret and a domain.
import { ManagementClient } from 'auth0';

var management = new ManagementClient({
domain: '{YOUR_TENANT_AND REGION}.[auth0.com](http://auth0.com/)',
clientId: '{YOUR_CLIENT_ID}',
clientSecret: '{YOUR_CLIENT_SECRET}',
});
  • Or, initialize the client class with an API v2 token and a domain.
import { ManagementClient } from 'auth0';

var management = new ManagementClient({
domain: '{YOUR_TENANT_AND REGION}.[auth0.com](http://auth0.com/)',
token: '{YOUR_API_V2_TOKEN}',
});