Kind: Interface
Source: packages/common/interfaces/features/nest-interceptor.interface.ts
Part of: Common
Interface providing access to the response stream.
CallHandler represents the downstream execution pipeline in a NestJS interceptor. It provides access to the response stream through handle(), allowing interceptors to transform, observe, or replace values returned by route handlers.
Diagram
mermaidgraph LR Client[Client Request] --> Interceptor[Nest Interceptor] Interceptor --> Handler[CallHandler] Handler --> Controller[Route Handler] Controller --> Stream[Observable Response Stream] Stream --> Interceptor Interceptor --> Client
Usage
tsimport {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
} from '@nestjs/common';
import { Observable, map } from 'rxjs';
@Injectable()
export class ResponseWrapperInterceptor implements NestInterceptor {
intercept(
context: ExecutionContext,
next: CallHandler,
): Observable<{ data: unknown }> {
return next.handle().pipe(
map((response) => ({
data: response,
})),
);
}
}
AI Coding Instructions
- Call
next.handle()to continue execution to the controller or next interceptor and receive anObservableresponse stream. - Use RxJS operators such as
map,tap,catchError, andtimeoutto modify or monitor responses without subscribing manually. - Return the transformed
Observable; do not callsubscribe()inside an interceptor. - Treat
CallHandleras the boundary between interceptor logic and the downstream route handler execution.
Used by
32 references from 32 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.
Imported by (32)
DataInterceptor—integration/graphql-code-first/src/common/interceptors/data.interceptor.ts:10Interceptor—integration/inspector/src/circular-hello/interceptors/logging.interceptor.ts:10TimeoutInterceptor—integration/inspector/src/common/interceptors/timeout.interceptor.ts:10LoggingInterceptor—integration/inspector/src/core/interceptors/logging.interceptor.ts:10TransformInterceptor—integration/inspector/src/core/interceptors/transform.interceptor.ts:14LoggingInterceptor—integration/inspector/src/request-chain/interceptors/logging.interceptor.ts:10PassthroughInterceptor—integration/nest-application/sse/src/app.controller.ts:28Interceptor—integration/scopes/src/circular-hello/interceptors/logging.interceptor.ts:10
…and 24 more.
Was this page helpful?