nestjs/nest · error · InvalidExceptionFilterException

Invalid exception filters (@UseFilters()).

Error message

Invalid exception filters (@UseFilters()).

What it means

Error "Invalid exception filters (@UseFilters())." thrown in nestjs/nest.

Source

Thrown at packages/websockets/exceptions/ws-exceptions-handler.ts:25

import { BaseWsExceptionFilter } from './base-ws-exception-filter';

/**
 * @publicApi
 */
export class WsExceptionsHandler extends BaseWsExceptionFilter {
  private filters: ExceptionFilterMetadata[] = [];

  public handle(exception: Error | WsException, host: ArgumentsHost) {
    const client = host.switchToWs().getClient();
    if (this.invokeCustomFilters(exception, host) || !client.emit) {
      return;
    }
    super.catch(exception, host);
  }

  public setCustomFilters(filters: ExceptionFilterMetadata[]) {
    if (!Array.isArray(filters)) {
      throw new InvalidExceptionFilterException();
    }
    this.filters = filters;
  }

  public invokeCustomFilters<T = any>(
    exception: T,
    args: ArgumentsHost,
  ): boolean {
    if (isEmpty(this.filters)) return false;

    const filter = selectExceptionFilterMetadata(this.filters, exception);
    filter && filter.func(exception, args);
    return !!filter;
  }
}

View on GitHub (pinned to 6ec0e2783d)

Solutions

  1. Pass valid exception filter classes or instances to @UseFilters(); each filter must implement ExceptionFilter (have a catch method).
  2. Do not pass plain objects, undefined, or non-filter values to @UseFilters().
  3. Ensure the filter class is decorated with @Catch() and properly imported.

Example fix

@Catch(WsException)
export class WsFilter implements ExceptionFilter {
  catch(exception: WsException, host: ArgumentsHost) { /* handle */ }
}
@UseFilters(WsFilter)
@WebSocketGateway()
export class EventsGateway {}

When it happens

Trigger: Thrown at packages/websockets/exceptions/ws-exceptions-handler.ts:25 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nestjs/nest@6ec0e2783d (2026-08-03). Data as JSON: /data/errors/2f20e1f61c830b80.json. Report an issue: GitHub.