Skip to content

RpcExceptionFilterMetadata

reference
1 min readUpdated

Kind: Interface

Source: packages/common/interfaces/exceptions/rpc-exception-filter-metadata.interface.ts

Part of: Common

RpcExceptionFilterMetadata describes the runtime metadata Nest uses to connect an RPC exception filter's catch method with the exception classes it handles. It is typically produced during exception-filter discovery and consumed by the RPC exception handling pipeline to select an appropriate filter for a thrown error.

Properties

PropertyType
funcRpcExceptionFilter['catch']
exceptionMetatypesType<any>[]

Diagram

mermaid
graph LR
  E[RPC handler throws exception] --> H[RPC exception handler]
  H --> M[RpcExceptionFilterMetadata]
  M --> T[exceptionMetatypes]
  M --> F[func: filter.catch]
  T -->|matches exception type| F
  F --> R[RPC error response]

Usage

ts
import { RpcException } from '@nestjs/microservices';
import type { RpcExceptionFilterMetadata } from '@nestjs/common/interfaces/exceptions/rpc-exception-filter-metadata.interface';

const rpcExceptionFilter = {
  catch(exception: RpcException) {
    return {
      status: 'error',
      message: exception.message,
    };
  },
};

const metadata: RpcExceptionFilterMetadata = {
  func: rpcExceptionFilter.catch,
  exceptionMetatypes: [RpcException],
};

// The RPC exception layer can use `exceptionMetatypes` to determine
// whether this filter should handle a thrown exception, then invoke `func`.

AI Coding Instructions

  • Keep func assigned to an exception filter's catch method and ensure its signature remains compatible with RpcExceptionFilter['catch'].
  • Populate exceptionMetatypes with exception constructors, not instances or string names.
  • Preserve the relationship between each filter callback and its handled exception types when creating or transforming metadata.
  • Use this metadata in RPC exception resolution paths; do not use it as a general HTTP or WebSocket exception-filter contract.

How it works

RpcExceptionFilterMetadata

RpcExceptionFilterMetadata is an exported TypeScript interface for one RPC exception-filter entry. It contains a filter callback and the exception constructor types associated with that callback. packages/common/interfaces/exceptions/rpc-exception-filter-metadata.interface.ts:4-7

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • RpcExceptionsHandlerpackages/microservices/exceptions/rpc-exceptions-handler.ts:13

Was this page helpful?

Download as PDF
RpcExceptionFilterMetadata — NestJS head-to-head