6

I have an async ngxs action that throwsError().

I would like the default error handling mechanism to ignore this thrown error because I will be handling it in my code via ofActionErrored(). However, for other actions, default error handling should still take place.

Right now, both the ofActionErrored() and default error handling (via Angular/Ionic) tries to deal with the error.

The alternative I can think of is to dispatch Xxx_SUCCESS and Xxx_ERROR actions from within the initially dispatched action, something I would like to avoid if i can help it.

Advice appreciated.

kctang
  • 10,894
  • 8
  • 44
  • 63

2 Answers2

3

There is a feature request that raised a similar concern at the NGXS repo. We've discussed in the core team meeting and we'll focus that for the next release. You can provide your feedback there: https://github.com/ngxs/store/issues/1691

1

You can use ofActionCompleted which as a result can provide the error, if there is one. An example taken from the code I am working on:

this.actions$.pipe(
  ofActionCompleted(GetMe)
).subscribe((data) => {
  const errorStatus = data.result.error['status'];

  if (!data.result.successful && errorStatus === 403) {
    this.snackbar.openFromComponent(TranslateSnakeBarComponent, {
      data: {message: 'USER_DISABLED'}
    });
  }
});
Spartak Lalaj
  • 429
  • 6
  • 13