Complete the code to import the Interceptor interface from NestJS.
import { [1] } from '@nestjs/common';
The NestInterceptor interface is imported from @nestjs/common to create interceptors.
Complete the code to implement the Interceptor interface in a class.
export class LoggingInterceptor implements [1] { }
To create an interceptor, the class must implement the NestInterceptor interface.
Fix the error in the intercept method signature by completing the parameter type.
intercept(context: [1], next: CallHandler): Observable<any> { return next.handle(); }
The intercept method receives an ExecutionContext parameter to access details about the current request.
Fill both blanks to correctly import and use CallHandler in the interceptor.
import { [1], CallHandler } from '@nestjs/common'; intercept(context: ExecutionContext, next: [2]): Observable<any> { return next.handle(); }
ExecutionContext and CallHandler are both imported from @nestjs/common and used in the intercept method.
Fill all three blanks to create a basic interceptor that logs before and after the request.
import { Injectable, [1], ExecutionContext, CallHandler } from '@nestjs/common'; import { [2] } from 'rxjs'; import { tap } from 'rxjs/operators'; @Injectable() export class LoggingInterceptor implements [3] { intercept(context: ExecutionContext, next: CallHandler): Observable<any> { console.log('Before...'); const now = Date.now(); return next.handle().pipe( tap(() => console.log(`After... ${Date.now() - now}ms`)) ); } }
The interceptor class is decorated with @Injectable(), implements NestInterceptor, and uses Observable from rxjs.