Bird
0
0

Identify the error in this LoggingInterceptor code:

medium📝 Troubleshoot Q14 of 15
NestJS - Interceptors
Identify the error in this LoggingInterceptor code:
intercept(context, next) {
  const now = Date.now();
  next.handle().pipe(
    tap(() => console.log(`Request took ${Date.now() - now}ms`))
  );
}
Atap operator is not imported
BIncorrect use of Date.now()
CMissing context parameter
DMissing return statement before next.handle()
Step-by-Step Solution
Solution:
  1. Step 1: Check the intercept method return

    The intercept method must return the observable from next.handle() to continue the request lifecycle.
  2. Step 2: Identify missing return

    The code calls next.handle().pipe(...) but does not return it, so the request will not proceed properly.
  3. Final Answer:

    Missing return statement before next.handle() -> Option D
  4. Quick Check:

    intercept must return next.handle() observable [OK]
Quick Trick: Always return next.handle() in intercept method [OK]
Common Mistakes:
  • Forgetting to return the observable
  • Misusing Date.now() for timing
  • Ignoring required parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes