Bird
0
0

Why does this interceptor cause a runtime error?

medium📝 Debug Q7 of 15
NestJS - Interceptors
Why does this interceptor cause a runtime error?
intercept(context, next) {
  return next.handle().pipe(map(data => data.toUpperCase()));
}

Assuming data is an object.
Apipe is not imported correctly
BtoUpperCase() is not a function on objects
Cnext.handle() returns a Promise, not Observable
Dcontext parameter is required to call toUpperCase()
Step-by-Step Solution
Solution:
  1. Step 1: Understand data type in map

    Data is an object, but toUpperCase() is a string method.
  2. Step 2: Identify the error cause

    Calling toUpperCase() on an object causes runtime error.
  3. Final Answer:

    toUpperCase() is not a function on objects -> Option B
  4. Quick Check:

    toUpperCase() only works on strings [OK]
Quick Trick: Check data type before calling string methods [OK]
Common Mistakes:
  • Assuming data is string always
  • Blaming pipe or next.handle()
  • Misusing context parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes