Bird
0
0

Given this ExceptionMappingInterceptor code snippet, what will be the output if the handler throws an error?

medium📝 component behavior Q13 of 15
NestJS - Interceptors
Given this ExceptionMappingInterceptor code snippet, what will be the output if the handler throws an error?
intercept(context, next) {
  return next.handle().pipe(
    catchError(err => {
      return throwError(() => new BadRequestException('Mapped error'));
    }),
  );
}
AThe original error is sent to the client
BNo error is sent; the request succeeds silently
CA BadRequestException with message 'Mapped error' is sent to the client
DA syntax error occurs and the app crashes
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the catchError block

    When an error occurs, catchError catches it and returns a new BadRequestException with a custom message.
  2. Step 2: Understand the effect on the client response

    The client receives the new BadRequestException with message 'Mapped error' instead of the original error.
  3. Final Answer:

    A BadRequestException with message 'Mapped error' is sent to the client -> Option C
  4. Quick Check:

    Error replaced by BadRequestException [OK]
Quick Trick: catchError replaces original error with mapped exception [OK]
Common Mistakes:
  • Thinking original error passes through unchanged
  • Assuming no error is sent and request succeeds
  • Confusing syntax error with runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes