Bird
0
0

Which of the following is the correct way to implement the intercept method in a NestJS LoggingInterceptor?

easy📝 Syntax Q12 of 15
NestJS - Interceptors
Which of the following is the correct way to implement the intercept method in a NestJS LoggingInterceptor?
Aintercept(context, next) { return next.handle(); }
Bintercept(context, next) { next.handle(); }
Cintercept(context) { return next.handle(); }
Dintercept(next) { return context.handle(); }
Step-by-Step Solution
Solution:
  1. Step 1: Recall the intercept method signature

    The intercept method receives two parameters: context and next. It must return next.handle() to continue the request lifecycle.
  2. Step 2: Check each option for correct syntax

    intercept(context, next) { return next.handle(); } correctly uses both parameters and returns next.handle(). Options A, C, and D either miss parameters or do not return the observable.
  3. Final Answer:

    intercept(context, next) { return next.handle(); } -> Option A
  4. Quick Check:

    intercept(context, next) returns next.handle() [OK]
Quick Trick: intercept always returns next.handle() with both parameters [OK]
Common Mistakes:
  • Omitting return statement
  • Missing one of the parameters
  • Calling handle on wrong object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes