Bird
0
0

Identify the error in this ExceptionMappingInterceptor code:

medium📝 Debug Q14 of 15
NestJS - Interceptors
Identify the error in this ExceptionMappingInterceptor code:
intercept(context, next) {
  return next.handle().pipe(
    catchError(err => {
      throw new HttpException('Error occurred', 400);
    }),
  );
}
ANo error; code is correct
BUsing throw inside catchError instead of returning an observable error
CIncorrect status code 400 instead of 500
DMissing import for HttpException
Step-by-Step Solution
Solution:
  1. Step 1: Understand catchError usage

    Inside catchError, you must return an observable error, not throw an error directly.
  2. Step 2: Identify correct error handling

    The code should return throwError(() => new HttpException(...)) instead of throwing.
  3. Final Answer:

    Using throw inside catchError instead of returning an observable error -> Option B
  4. Quick Check:

    catchError must return observable error, not throw [OK]
Quick Trick: Return throwError inside catchError, don't throw directly [OK]
Common Mistakes:
  • Throwing error directly inside catchError
  • Ignoring observable error return requirement
  • Assuming status code 400 is wrong here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes