{"record":{"id":"328bb715954b000f","repo":"nodejs/node","slug":"handler-must-be-an-object","errorCode":null,"errorMessage":"handler must be an object","messagePattern":"handler must be an object","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/handler/decorator-handler.js","lineNumber":16,"sourceCode":"'use strict'\n\nconst assert = require('node:assert')\n\n/**\n * @deprecated\n */\nmodule.exports = class DecoratorHandler {\n  #handler\n  #onCompleteCalled = false\n  #onErrorCalled = false\n  #onResponseStartCalled = false\n\n  constructor (handler) {\n    if (typeof handler !== 'object' || handler === null) {\n      throw new TypeError('handler must be an object')\n    }\n    this.#handler = handler\n  }\n\n  onRequestStart (...args) {\n    this.#handler.onRequestStart?.(...args)\n  }\n\n  onRequestUpgrade (...args) {\n    assert(!this.#onCompleteCalled)\n    assert(!this.#onErrorCalled)\n\n    return this.#handler.onRequestUpgrade?.(...args)\n  }\n\n  onResponseStart (...args) {\n    assert(!this.#onCompleteCalled)\n    assert(!this.#onErrorCalled)","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/handler/decorator-handler.js#L1-L34","documentation":"Thrown by the DecoratorHandler constructor when handler is not a non-null object. DecoratorHandler is a deprecated wrapper that forwards DispatchHandler callbacks to an inner handler; it needs an object to delegate to. The guard is typeof handler !== 'object' || handler === null. Note this throws TypeError, not InvalidArgumentError.","triggerScenarios":"Constructing new DecoratorHandler(undefined), new DecoratorHandler(null), or new DecoratorHandler('something'). Passing a function where an object was expected also fails because typeof function === 'function', not 'object'.","commonSituations":"Forgetting the inner handler argument; passing a callback in place of a handler object; migrating off the deprecated DecoratorHandler and mis-wiring arguments; partial refactor leaving handler unset on a branch.","solutions":["Pass a non-null object implementing the DispatchHandler interface.","Since DecoratorHandler is deprecated, prefer a custom handler class or the modern interceptor APIs.","Default the inner handler to a no-op object { } if forwarding is optional.","Ensure the value is set on all code paths before constructing the decorator."],"exampleFix":"// before\nnew DecoratorHandler()\n// after\nnew DecoratorHandler({ onRequestStart() {}, onResponseEnd() {} })","handlingStrategy":"type-guard","validationCode":"if (handler == null || typeof handler !== 'object') {\n  throw new TypeError('DecoratorHandler requires a non-null object handler')\n}\nnew DecoratorHandler(handler)","typeGuard":"function isHandlerObject(v) { return v != null && typeof v === 'object' }","tryCatchPattern":null,"preventionTips":["DecoratorHandler is deprecated; prefer modern interceptor APIs for new code.","Always pass an inner DispatchHandler object as the first argument.","Default to a no-op object when forwarding is optional."],"tags":["undici","handler","decorator","deprecated","invalid-arg","typeerror"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}