typescripterror-handlingrxjsngrxngrx-effects

NgRx effect "dies" after 10 errors


Using NgRx in an Angular project, I have the following effects:

let i = 0

@Injectable()
export class Effects {
    testEffect$ = createEffect(
        () =>
            this.actions$.pipe(
                tap(() => console.log("action number:", i += 1)),
                mergeMap(() => throwError(() => "")),
            ),
        { dispatch: false, useEffectsErrorHandler: true },
    )

    // ...

For any action that is dispatched, the effect logs a statement and then replaces its content by an error.

This works for 10 actions. After exactly 10 actions have been dispatched, the 11th action will not cause the console.log anymore. In fact, no effect is executed at all anymore and Redux Dev tools also do not record any actions from that point on.

I realize that if I expect errors to occur, I should use catchError to gracefully handle them. However, it worries me that if there is an error I do not handle, it can break my entire application after occurring a few times.

Why does this happen? Is there a way I can prevent it?


Solution

  • This is the intended behavior.

    We found this a good starting point for most projects.

    You can override this behavior by creating your own error handler, and configuring Effects to use it.

    For more info and an example see https://ngrx.io/guide/effects/lifecycle#customizing-the-effects-error-handler