Bird
0
0

Identify the error in this effect code:

medium📝 Debug Q14 of 15
Angular - State Management
Identify the error in this effect code:
saveData$ = createEffect(() => this.actions$.pipe(
  ofType(saveData),
  switchMap(action => this.api.save(action.payload)),
  map(() => saveDataSuccess()),
  catchError(error => saveDataFailure({ error }))
));
AThe <code>catchError</code> operator should return an observable
BThe <code>switchMap</code> should not use <code>action</code> parameter
CThe <code>map</code> operator must return the original action
DThe effect should not use <code>createEffect</code> function
Step-by-Step Solution
Solution:
  1. Step 1: Check catchError usage

    The catchError operator must return an observable, but here it returns an action object directly.
  2. Step 2: Correct catchError return

    Wrapping the action in of() makes it an observable, fixing the error.
  3. Final Answer:

    The catchError operator should return an observable -> Option A
  4. Quick Check:

    catchError must return observable [OK]
Quick Trick: Always wrap catchError return in of() to return observable [OK]
Common Mistakes:
  • Returning plain object instead of observable in catchError
  • Misusing switchMap parameters
  • Thinking map must return original action

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes