Bird
0
0

Given this LoggingInterceptor code snippet, what will be logged when a request is handled?

medium📝 Command Output Q13 of 15
NestJS - Interceptors
Given this LoggingInterceptor code snippet, what will be logged when a request is handled?
intercept(context, next) {
  const now = Date.now();
  return next.handle().pipe(
    tap(() => console.log(`Request took ${Date.now() - now}ms`))
  );
}
ALogs the time taken to process the request in milliseconds
BLogs the request URL only
CLogs the response body content
DLogs an error message if the request fails
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the timing logic

    The code records the current time before the request is handled, then logs the difference after the response is sent.
  2. Step 2: Understand the logged message

    The console.log outputs "Request took Xms" where X is the elapsed time in milliseconds.
  3. Final Answer:

    Logs the time taken to process the request in milliseconds -> Option A
  4. Quick Check:

    LoggingInterceptor measures request duration [OK]
Quick Trick: Look for Date.now() difference to find elapsed time [OK]
Common Mistakes:
  • Assuming it logs request URL or body
  • Thinking it logs errors only
  • Ignoring the timing calculation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes