Bird
0
0

Given this interceptor code snippet, what will be the transformed response?

medium📝 component behavior Q13 of 15
NestJS - Interceptors
Given this interceptor code snippet, what will be the transformed response?
intercept(context, next) {
  return next.handle().pipe(map(data => ({ result: data }))); 
}
A{ data: originalData }
BoriginalData
C{ result: originalData }
DAn error will occur
Step-by-Step Solution
Solution:
  1. Step 1: Understand the interceptor's map function

    The map operator wraps the original data inside an object with key 'result'.
  2. Step 2: Predict the transformed output

    The response will be an object: { result: originalData }.
  3. Final Answer:

    { result: originalData } -> Option C
  4. Quick Check:

    map wraps data in { result: ... } [OK]
Quick Trick: map operator wraps data in new object key [OK]
Common Mistakes:
  • Assuming original data is unchanged
  • Confusing key name as 'data' instead of 'result'
  • Expecting an error from this code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes