Bird
0
0

What is wrong with this interceptor code that tries to transform the response?

medium📝 Debug Q14 of 15
NestJS - Interceptors
What is wrong with this interceptor code that tries to transform the response?
intercept(context, next) {
  next.handle().pipe(map(data => data.trim()));
}
Anext.handle() should not be called
Bmap operator cannot be used inside intercept
Ctrim() is not a valid method on data
DMissing return statement for the observable
Step-by-Step Solution
Solution:
  1. Step 1: Check interceptor return value

    Interceptors must return the observable from next.handle().pipe(...).
  2. Step 2: Identify missing return

    The code calls next.handle().pipe(...) but does not return it, so the response is undefined.
  3. Final Answer:

    Missing return statement for the observable -> Option D
  4. Quick Check:

    Always return next.handle().pipe(...) [OK]
Quick Trick: Always return the observable from intercept method [OK]
Common Mistakes:
  • Forgetting to return the observable
  • Assuming map cannot be used in intercept
  • Misusing trim() on non-string data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes