{"record":{"id":"717d4f6252684b85","repo":"nodejs/node","slug":"invalid-interceptor-expected-function-received","errorCode":null,"errorMessage":"invalid interceptor, expected function received ${typeof interceptor}","messagePattern":"invalid interceptor, expected function received (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/dispatcher/dispatcher.js","lineNumber":28,"sourceCode":"    throw new Error('not implemented')\n  }\n\n  destroy () {\n    throw new Error('not implemented')\n  }\n\n  compose (...args) {\n    // So we handle [interceptor1, interceptor2] or interceptor1, interceptor2, ...\n    const interceptors = Array.isArray(args[0]) ? args[0] : args\n    let dispatch = this.dispatch.bind(this)\n\n    for (const interceptor of interceptors) {\n      if (interceptor == null) {\n        continue\n      }\n\n      if (typeof interceptor !== 'function') {\n        throw new TypeError(`invalid interceptor, expected function received ${typeof interceptor}`)\n      }\n\n      dispatch = interceptor(dispatch)\n\n      if (dispatch == null || typeof dispatch !== 'function' || dispatch.length !== 2) {\n        throw new TypeError('invalid interceptor')\n      }\n    }\n\n    return new Proxy(this, {\n      get: (target, key) => key === 'dispatch' ? dispatch : target[key]\n    })\n  }\n}\n\nmodule.exports = Dispatcher\n","sourceCodeStart":10,"sourceCodeEnd":45,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/dispatcher/dispatcher.js#L10-L45","documentation":"TypeError thrown by Dispatcher.compose() when an interceptor is not null/undefined and is not a function. Interceptors must be functions of shape (dispatch) => newDispatch. Nullish interceptors are silently skipped, but any other non-function type (object, number, string) is rejected.","triggerScenarios":"Calling `client.compose([{}])`, `client.compose(42)`, `client.compose('redirect')`, or passing a config object where an interceptor function is expected. Fires at dispatcher.js:27-28.","commonSituations":"Passing an interceptor-options object instead of the interceptor factory (e.g. passing { maxRedirections: 10 } instead of redirect({ maxRedirections: 10 })); spreading an array that contains a stray non-function; importing an interceptor that defaulted to undefined and replacing it with a config object.","solutions":["Pass interceptor factory functions, e.g. client.compose(redirect({ maxRedirections: 10 })).","Filter nullish entries before compose if your interceptor list is dynamic.","Verify each import resolves to a function before adding it to the chain."],"exampleFix":"// before\nclient.compose([{ maxRedirections: 10 }])\n// after\nconst { redirect } = require('undici')\nclient.compose(redirect({ maxRedirections: 10 }))","handlingStrategy":"type-guard","validationCode":"function composeSafe(client, interceptors) {\n  const list = (Array.isArray(interceptors) ? interceptors : [interceptors])\n    .filter(i => typeof i === 'function');\n  if (list.length !== interceptors.length) {\n    throw new TypeError('all interceptors must be functions');\n  }\n  return client.compose(list);\n}","typeGuard":"typeof interceptor === 'function'","tryCatchPattern":null,"preventionTips":["Pass interceptor factories, not config objects.","Filter nullish entries only; reject non-functions loudly.","Verify each imported interceptor resolves to a function."],"tags":["undici","dispatcher","interceptor","compose","typeerror"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}