Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we handle ngxs @Action errors via ofActionErrored() without going to default "ErrorHandler"?

Tags:

ngxs

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.

like image 980
kctang Avatar asked Jun 04 '18 04:06

kctang


2 Answers

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

like image 174
Mateus Carniatto Avatar answered Nov 11 '22 16:11

Mateus Carniatto


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'}
    });
  }
});
like image 38
Spartak Lalaj Avatar answered Nov 11 '22 14:11

Spartak Lalaj