Bird
0
0

Identify the error in this LoggingInterceptor code snippet:

medium📝 Troubleshoot Q6 of 15
NestJS - Interceptors
Identify the error in this LoggingInterceptor code snippet:
intercept(context: ExecutionContext, next: CallHandler): void {
  console.log('Request started');
  next.handle();
  console.log('Request ended');
}
Aintercept must return an Observable, not void
Bconsole.log statements are not allowed in interceptors
Cnext.handle() should be called before console.log
DExecutionContext parameter is missing
Step-by-Step Solution
Solution:
  1. Step 1: Check method return type

    intercept must return Observable to handle async flow.
  2. Step 2: Identify the error in code

    Here, intercept returns void, which breaks the interceptor contract.
  3. Final Answer:

    intercept must return an Observable, not void -> Option A
  4. Quick Check:

    intercept return type = Observable [OK]
Quick Trick: intercept must return Observable to work properly [OK]
Common Mistakes:
  • Returning void instead of Observable
  • Misplacing console.log calls
  • Ignoring ExecutionContext parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes