{"id":"21a973e17c264fa4","repo":"nestjs/nest","slug":"method-not-implemented","errorCode":null,"errorMessage":"Method not implemented.","messagePattern":"Method not implemented\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/microservices/client/client-proxy.ts","lineNumber":71,"sourceCode":"\n  /**\n   * Establishes the connection to the underlying server/broker.\n   */\n  public abstract connect(): Promise<any>;\n  /**\n   * Closes the underlying connection to the server/broker.\n   */\n  public abstract close(): any;\n  /**\n   * Registers an event listener for the given event.\n   * @param event Event name\n   * @param callback Callback to be executed when the event is emitted\n   */\n  public on<\n    EventKey extends keyof EventsMap = keyof EventsMap,\n    EventCallback extends EventsMap[EventKey] = EventsMap[EventKey],\n  >(event: EventKey, callback: EventCallback) {\n    throw new Error('Method not implemented.');\n  }\n  /**\n   * Returns an instance of the underlying server/broker instance,\n   * or a group of servers if there are more than one.\n   */\n  public abstract unwrap<T>(): T;\n\n  /**\n   * Send a message to the server/broker.\n   * Used for message-driven communication style between microservices.\n   * @param pattern Pattern to identify the message\n   * @param data Data to be sent\n   * @returns Observable with the result\n   */\n  public send<TResult = any, TInput = any>(\n    pattern: any,\n    data: TInput,\n  ): Observable<TResult> {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/packages/microservices/client/client-proxy.ts#L53-L89","documentation":"Thrown by the base ClientProxy.on() default implementation. ClientProxy declares on() as a non-abstract method that always throws 'Method not implemented.' so that subclasses opt in by overriding it (ClientRedis, ClientRMQ, ClientMQTT, ClientTCP, ClientNATS override it; ClientKafka overrides with its own 'not supported' error). Hitting this base message means you are using a client class whose transport does not implement event subscription via on() — typically the legacy ClientProxyDirect or a custom subclass that never overrode on().","triggerScenarios":"Calling on() on a ClientProxy subclass that did not override it (e.g., a custom client extending ClientProxy directly, or ClientProxyFactory returning a client type that has no on() override). Writing generic code that calls on() on any ClientProxy without checking the concrete transport.","commonSituations":"Custom ClientProxy subclass authored without overriding on()/unwrap()/connect(). Code that assumes every ClientProxy supports the on() API like the Redis/TCP transports do. Stale references to a client type whose on() was never implemented.","solutions":["Override on() in your custom ClientProxy subclass, or use one of the built-in transport clients that implement it (Redis/RMQ/MQTT/TCP/NATS).","If you only need connection status, subscribe to client.status instead of on().","Switch to a transport client that supports on(), or implement the listener against the unwrapped native client."],"exampleFix":"// before\nclass MyClient extends ClientProxy {\n  connect() { return Promise.resolve(); }\n  close() {}\n  unwrap<T>(): T { return null as T; }\n}\nnew MyClient().on('connect', fn); // throws 'Method not implemented.'\n\n// after\nclass MyClient extends ClientProxy {\n  on(event, cb) { this._status$.subscribe(s => s === 'connected' && cb()); }\n  // ...\n}","handlingStrategy":"type-guard","validationCode":"// Only call on() on clients that implement it\nconst transportsWithoutOn = new Set([/* custom ClientProxy subclasses without on() */]);\nfunction supportsOn(client: any): boolean {\n  return client && typeof client.on === 'function'\n    && client.on !== ClientProxy.prototype.on;\n}\nif (supportsOn(client)) client.on('connect', fn);\nelse client.status.subscribe(s => { /* ... */ });","typeGuard":"import { ClientProxy } from '@nestjs/microservices';\nconst hasOverriddenOn = (c: any): boolean =>\n  c instanceof ClientProxy && c.on !== ClientProxy.prototype.on;","tryCatchPattern":"try {\n  client.on(event, cb);\n} catch (e) {\n  if (/Method not implemented/.test(e?.message)) {\n    client.status.subscribe(s => { /* handle via status */ });\n  } else throw e;\n}","preventionTips":["If you subclass ClientProxy, override on() or rely on status.","Prefer client.status over on() for portable connection monitoring.","Avoid generic on() across unknown client types; branch by transport."],"tags":["client-proxy","events","api-misuse","typescript","custom-transport"],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}