Bird
0
0

You want to create a LoggingInterceptor that logs request duration only if it exceeds 500ms. How would you implement this?

hard📝 Workflow Q9 of 15
NestJS - Interceptors
You want to create a LoggingInterceptor that logs request duration only if it exceeds 500ms. How would you implement this?
AInside tap, check if duration > 500ms before logging
BUse a guard to block requests taking longer than 500ms
CSet a timeout of 500ms on next.handle() Observable
DLog all requests and filter logs externally for duration > 500ms
Step-by-Step Solution
Solution:
  1. Step 1: Measure request duration inside intercept

    Record start time before next.handle(), calculate duration in tap.
  2. Step 2: Add condition to log only if duration exceeds 500ms

    Use if statement inside tap to log selectively.
  3. Final Answer:

    Inside tap, check if duration > 500ms before logging -> Option A
  4. Quick Check:

    Conditional logging done inside tap operator [OK]
Quick Trick: Use conditional inside tap to log selectively [OK]
Common Mistakes:
  • Using guards for timing logic
  • Applying timeout incorrectly
  • Logging all requests without filtering

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes