-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃殌[FEATURE]: Make choose to forward or not the errors to the global handler #1691
Comments
@XavierDupessey Thank you for submitting this issue. |
For a particular action, could it be part of the ActionOptions object?
But I would prefer an option to set it globally (with NgxsConfig maybe?). I think it would be annoying to put |
One option we could have a look at is to detect when an action is being monitored by an |
Detecting if an action is being monitored by I prefer a more declarative approach, with ability to override like:
|
another option could be to add a param to |
It seems like there is currently no way to return expected errors from an action without them being caught by the global error handler. If, for example, I have two components that dispatch the same action but handle potential errors differently, I currently have no way of doing this, without the error also being handled by the global error handler. (Think adding a todo from a dialog component and from a normal page component. The error should be handling differently, e.g. closing the dialog vs navigating to a different page.) This feature would solve the issue. |
I'm in need of this feature, too. My use case is that some errors get handled in a custom way, inside the component. However, any errors that are not custom handled, should bubble up and are handled in a more general way by a custom ErrorHandler, typically by redirecting to an error page. Because the @action calls the ErrorHandler in case of error, the custom error handling code of the component is called too late: the ErrorHandler already redirected the user to a general error page and no custom error can be shown. Rather than configuring the @action handler whether to call ErrorHandler or not, it makes much more sense to me to pass this configuration when dispatching the action, typically in the component. It is the component that 'knows' whether it's going to handle the error itself, or it would rather rely on the general ErrorHandler to do so. It's been quite a while, any updates on this issue? |
I'm curious to find out why the decision was made to explicitly call the Angular ErrorHandler from action handlers. Am I wrong to assume that any errors that are unhandled, eventually bubble up and are handled by the Angular ErrorHandler anyway? This related issue seems to support my assumption: #803 |
Awaiting this feature request, here's a way to bypass the undesired behaviour of errors being processed by the To summarize: Desired behaviour:
Observed behaviour:
Solution: To do this, write an NgxsPlugin that hooks into the ngxs pipe:
Write a custom ErrorHandler:
Provide both the plugin and the custom
It's hacky, but at least it enables you to let the dispatcher (rather than the action handler) decide whether it wants to catch/handle the error or not, and have a mechanism to handle errors that aren't caught anywhere. |
I am against calling this a "feature". This is a clearly a bug. In pure theory, you can divide exception in 2 general groups, expected from which you can recover, or the ones (expected or unexpected) from which you can not recover. We are using Angular's global error handler as a way to catch exceptions from which we can not recover. This is perfectly normal developer strategy, especially for us which are coming from languages such as Java, C#, PHP, etc... using frameworks like Symfony, per example. Global error handlers are used as final guard/logger for all non-handled exception. We use it to log error, notify admin to escalate issue and to show end user some kind of apologetic message for the issue. Therefore if code below:
produces an error in global handler - we automatically assume that there is a bug in NGXS. I was shocked after hours of debugging that this was per design. For me - this was a "piece of magic" that ignores my "catch" of expected error and forwarding it to undesired piece of application. If designed idea was to have a "sink" where all errors from actions are pushed, Angular's global error handler is the last place to do so. Thanks @fikkatra for idea how to deal with this issue. Addendum - I have stumbled upon the following suggestion "catch error in action handler and set state store to some kind of error state, put some error flag to true". This is terrible idea - I have invoked an action to transition state from state A to state B. Transition could not occur because of temporarily problem, but I can recover (invoke action again per example, login form is clear example). Having "error" flag in store just makes things complicated and simple, trivial code: try { becomes unnecessarily complicated because now I have to deal with "error" state as well. |
Yep, I agree this was a bug, and not even a feature. Because the error is handled twice if you handle it explicitly through I released a bug fix and it's available under |
This has been fixed as part of the v3.7.6 release. |
I'm submitting a...
Current behavior
If we don't want to catch the errors directly in the actions to handle them with ofActionErrored, they get actually handled twice: once by ofActionErrored and once by the global error handler.
Expected behavior
I think we should be able to decide if NGXS should forward the errors to the global error handler or not. Another possibility could be to wrap them in a custom error object (e.g. UnhandledNgxsActionError) to be able to filter them in the handler.
Minimal reproduction of the problem with instructions
Environment
The text was updated successfully, but these errors were encountered: