Bird
0
0

Which of the following is the correct syntax to implement the intercept method in a NestJS interceptor?

easy📝 Syntax Q3 of 15
NestJS - Interceptors
Which of the following is the correct syntax to implement the intercept method in a NestJS interceptor?
Aintercept(next: CallHandler, context: ExecutionContext): Promise<any> { return next.handle(); }
Bintercept(context: ExecutionContext, next: CallHandler): Observable<any> { return next.handle(); }
Cintercept(context: ExecutionContext): Observable<any> { return context.handle(); }
Dintercept(): void { console.log('Intercepted'); }
Step-by-Step Solution
Solution:
  1. Step 1: Recall the intercept method signature

    It takes ExecutionContext and CallHandler as parameters and returns an Observable.
  2. Step 2: Check each option's signature and return type

    Only intercept(context: ExecutionContext, next: CallHandler): Observable { return next.handle(); } matches the correct signature and returns next.handle() properly.
  3. Final Answer:

    intercept(context: ExecutionContext, next: CallHandler): Observable { return next.handle(); } -> Option B
  4. Quick Check:

    Correct intercept signature = intercept(context: ExecutionContext, next: CallHandler): Observable { return next.handle(); } [OK]
Quick Trick: intercept(context, next) returns next.handle() Observable [OK]
Common Mistakes:
  • Swapping parameter order
  • Returning Promise instead of Observable
  • Missing parameters or wrong return type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes