Bird
0
0

Consider this LoggingInterceptor snippet:

medium📝 Predict Output Q4 of 15
NestJS - Interceptors
Consider this LoggingInterceptor snippet:
intercept(context: ExecutionContext, next: CallHandler): Observable {
  const start = Date.now();
  return next.handle().pipe(
    tap(() => console.log(`Processed in ${Date.now() - start}ms`))
  );
}

What will be logged when a request completes?
ANo output will be logged
BThe request URL and method
COnly the start timestamp
DThe time in milliseconds it took to process the request
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the code

    The interceptor records the start time before calling next.handle().
  2. Step 2: Understand tap operator

    tap logs the difference between current time and start time after the request completes.
  3. Final Answer:

    The time in milliseconds it took to process the request -> Option D
  4. Quick Check:

    Logs duration, not URL or method. [OK]
Quick Trick: tap logs after observable completes, showing duration [OK]
Common Mistakes:
  • Expecting URL or method to be logged without explicit code
  • Thinking tap logs before request completion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes