Bird
0
0

What will be the output of this NestJS interceptor?

medium📝 component behavior Q4 of 15
NestJS - Interceptors
What will be the output of this NestJS interceptor?
intercept(context, next) {
  return next.handle().pipe(map(data => ({ status: 'success', payload: data })));
}
AThe response will be unchanged
BThe response will be wrapped inside an object with 'status' and 'payload' keys
CThe response will be converted to a string
DThe response will be an array containing the original data
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the map operator

    The map operator wraps the original data inside a new object with keys 'status' and 'payload'.
  2. Step 2: Understand the interceptor return

    The interceptor returns an Observable that emits this transformed object.
  3. Final Answer:

    The response will be wrapped inside an object with 'status' and 'payload' keys -> Option B
  4. Quick Check:

    Response is wrapped correctly [OK]
Quick Trick: map operator wraps response in new object [OK]
Common Mistakes:
  • Assuming the response remains unchanged
  • Thinking the response is converted to string
  • Believing the response becomes an array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes