How to handle NGXS action errors from the dispatching component?

  angular, ngxs, redux

Given I have a component accessible by a route and a dialog. They both dispatch the same action, for example AddTodo. So I might either add todos from a page (the routed component) or at another place from the dialog.

If during the backend request for adding a todo an error occurs, I want to handle it differently depending on whether the action was dispatched from the page or dialog, e.g. navigating to a different route from the page vs closing the dialog.

Since I have a global error handler that is catching all uncaught exceptions so the application doesn’t crash and the user sees a meaningful message, this error handler is always triggered if I don’t catch the error from inside the state (in the corresponding @Action annotated method). This however does not allow for my described use-case.

How would I solve this in a clean way?

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.