Bird
0
0

How can you use catchError to log an error and then rethrow it to be handled elsewhere?

hard🚀 Application Q9 of 15
Angular - RxJS Operators
How can you use catchError to log an error and then rethrow it to be handled elsewhere?
AcatchError(err => { console.error(err); return of(err); })
BcatchError(err => { console.error(err); return throwError(() => err); })
CcatchError(err => throwError(err))
DcatchError(err => { throw err; })
Step-by-Step Solution
Solution:
  1. Step 1: Log error inside catchError

    Use console.error(err) to log the error.
  2. Step 2: Rethrow error as Observable

    Return throwError(() => err) to rethrow error as Observable for further handling.
  3. Final Answer:

    catchError(err => { console.error(err); return throwError(() => err); }) -> Option B
  4. Quick Check:

    Log then rethrow error as Observable with throwError [OK]
Quick Trick: Log error then return throwError to rethrow inside catchError [OK]
Common Mistakes:
MISTAKES
  • Returning plain error instead of Observable
  • Throwing error directly inside catchError
  • Not logging error before rethrow

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes