Bird
0
0

You want to retry an HTTP request 3 times before handling errors with catchError. Which of the following RxJS pipelines correctly implements this?

hard📝 component behavior Q8 of 15
Angular - RxJS Operators
You want to retry an HTTP request 3 times before handling errors with catchError. Which of the following RxJS pipelines correctly implements this?
AhttpRequest$.pipe(catchError(err => retry(3)), of('Failed'))
BhttpRequest$.pipe(catchError(err => of('Failed')), retry(3))
ChttpRequest$.pipe(retry(3, catchError(err => of('Failed'))))
DhttpRequest$.pipe(retry(3), catchError(err => of('Failed after retries')))
Step-by-Step Solution
Solution:
  1. Step 1: Use retry before catchError

    The retry operator should be placed before catchError to attempt retries before handling errors.
  2. Step 2: catchError handles errors after retries

    After retry attempts fail, catchError handles the error and returns a fallback Observable.
  3. Step 3: Validate syntax

    httpRequest$.pipe(retry(3), catchError(err => of('Failed after retries'))) correctly chains retry(3) then catchError returning of('Failed after retries').
  4. Final Answer:

    httpRequest$.pipe(retry(3), catchError(err => of('Failed after retries'))) -> Option D
  5. Quick Check:

    retry before catchError, catchError returns Observable [OK]
Quick Trick: Place retry before catchError in pipe [OK]
Common Mistakes:
MISTAKES
  • Placing catchError before retry
  • Passing catchError as argument to retry
  • Returning non-Observable in catchError

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes