Bird
0
0

Identify the error in this Exception Mapping Interceptor code: ```typescript intercept(context, next) { next.handle().pipe( catchError(err => { return throwError(() => new Error('Mapped error')); }), ); } ```

medium📝 Debug Q6 of 15
NestJS - Interceptors
Identify the error in this Exception Mapping Interceptor code: ```typescript intercept(context, next) { next.handle().pipe( catchError(err => { return throwError(() => new Error('Mapped error')); }), ); } ```
AthrowError should not be used inside interceptors
BThe observable returned by next.handle() is not returned from intercept method
CcatchError operator is used incorrectly without arguments
DThe Error class cannot be used inside throwError
Step-by-Step Solution
Solution:
  1. Step 1: Check intercept method return

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

    Code calls next.handle().pipe(...) but does not return it, breaking the interceptor chain.
  3. Final Answer:

    The observable returned by next.handle() is not returned from intercept method -> Option B
  4. Quick Check:

    Return observable chain in intercept method [OK]
Quick Trick: Always return next.handle().pipe(...) in intercept [OK]
Common Mistakes:
  • Forgetting to return the observable
  • Misusing catchError syntax
  • Thinking throwError is invalid here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes