Bird
0
0

Identify the error in this interceptor code:

medium📝 Debug Q6 of 15
NestJS - Interceptors
Identify the error in this interceptor code:
intercept(context, next) {
  return next.handle().pipe(map(data => data * 2));
}

Assuming the controller returns an object, what is wrong?
AMultiplying an object by 2 causes a runtime error
Bmap operator is not imported
Cintercept method missing async keyword
Dnext.handle() should be awaited
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the map function logic

    The code tries to multiply data by 2, but data is an object, not a number.
  2. Step 2: Understand JavaScript behavior

    Multiplying an object by a number results in NaN or runtime error depending on context.
  3. Final Answer:

    Multiplying an object by 2 causes a runtime error -> Option A
  4. Quick Check:

    Cannot multiply object by number directly [OK]
Quick Trick: Check data type before arithmetic in map [OK]
Common Mistakes:
  • Assuming map must be async
  • Thinking next.handle() returns a promise to await
  • Ignoring data type in map function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes