Bird
0
0

Examine this effect code:

medium📝 Debug Q6 of 15
Angular - State Management
Examine this effect code:
saveData$ = createEffect(() => this.actions$.pipe(
  ofType('SAVE_DATA'),
  switchMap(action => this.api.save(action.payload)),
  map(() => ({ type: 'SAVE_SUCCESS' }))
))

What is a potential issue with this effect assuming api.save returns an observable?
AIt dispatches an action without a payload
BIt uses switchMap instead of mergeMap
CIt does not handle errors from the API call
DIt listens to the wrong action type
Step-by-Step Solution
Solution:
  1. Step 1: Analyze error handling

    The effect calls api.save but does not catch errors, so failures will not dispatch failure actions.
  2. Step 2: Evaluate other options

    Using switchMap is valid here; dispatching an action without payload is acceptable if no data is needed; action type is correct.
  3. Final Answer:

    It does not handle errors from the API call -> Option C
  4. Quick Check:

    Always handle errors in effects to avoid silent failures. [OK]
Quick Trick: Effects must handle API errors to dispatch failure actions. [OK]
Common Mistakes:
  • Ignoring error handling in effects
  • Assuming switchMap is always wrong
  • Expecting payload in success action unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes