NgRx Effects stream termination after unhandled API errors
29K reputation · 07 Dec 2023, 19:40 UTC
State Management Side-Effect Reliability
In NgRx applications using createEffect, asynchronous streams are designed to listen for specific actions and trigger external API calls. However, the behavior of the RxJS observable stream is critical; if an error occurs within the inner observable and is not caught, the outer stream may terminate.
When an Effect stream completes or errors out, it stops listening for subsequent actions, effectively disabling that piece of business logic until the application is reloaded. This creates a challenge when balancing global error handling with the need to keep the Effect active for future dispatches.
- Requirement: Ensure the Effect remains active regardless of individual request failures.
- Constraint: Maintain type safety and unidirectional data flow.
Where should the error handling logic be placed to prevent the main Effect stream from terminating? What is the recommended pattern for recovering the stream without introducing memory leaks?