-
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
馃悶[BUG]: ErrorHandler triggered twice on one action #803
Comments
create stackblitz example |
I'll try. Is there a example app with ngxs which I can copy on stackblitz? |
Here is working example: https://stackblitz.com/edit/ngxs-error-throw?file=src/app/app.component.ts |
Try to catch the error inside pipe.
|
But now it will never get to |
I think the errors are emitted from two functions one from the subscribe method inside app.component and other from the action
just tried this and i can see the error |
@markwhitfeld @amcdnl any comments on this issue? |
Having problems with this as well. I'd like to have the global error handler as a fallback for when the error is not dealt with in the component. But the error is triggered twice, once on the subscribe of the dispatch and also on the global error handler. Imo that is actually wrong behavior. The global error handler should only be called for unhandled errors. I seriously ask myself how others are dealing with error handling + ngxs |
Same feeling. This is the same issue as #781 and #1145. Personally, I tag errors that are re-thrown from an action handler so I can then swallow them in my global error handler. I basically just append I've also started to do a lot less work in NGXS states than I used to. For instance, I try to call webservices and catch error responses outside of NGXS, which actually makes more sense in most cases. I end up not having to catch errors inside NGXS action handlers very often. |
I've also had a damn headache regarding this issue as my global error handler was printing in console 2 times the same error. |
Just tested if this issue is fixed with the latest version: it is not. Even though in my component I've handled the exception, it still reaches global error handler. this.store.dispatch(new Login()).subscribe(
() => {
console.log('Success');
},
() => {
console.log('Error is handled here');
},
); |
Originally the issue was not about this. () => {
console.log('Error is handled here');
} This is not an |
Fair enough @arturovt I saw another comment with identical snippet in this thread and assumed this issue would cover it as well (#803 (comment)). Any suggestions how to move error handling into components? Since is many cases it doesn't make sense to globally handle errors in actions, but it makes sense to handle them on a case-by-case basis in the consumer component. |
Trust me, I really understand your case and what you'd want to achieve. This logic (related to the Since we are convinced that we cannot remove this logic then we could try to find some trade-offs. I remember that my solution was just to not pay attention to those errors from the |
@arturovt perhaps this is something to consider for v4? 馃槂 My current logic is to suppress every But at least that works for now. :) |
@MatissJanis y, you're right, that could be a plan for v4. |
Why is this issue closed? It seems like there's no fix and no workaround? |
For those of you, like me, still running into the issue 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. |
Same question - why is this closed? Makes no sense, valid reasons are provided for its resolution. Thanks @fikkatra, we will flag error in similar way. |
I'm submitting a...
Current behavior
I have action that retrives data from backend and throws error.
I run action like this:
Action itself is something like this:
I have my custom
ErrorHandler
and it is invoked twice. As I read it's because observable has two or more subscribers: https://stackoverflow.com/questions/47898101/why-my-global-error-handler-get-invoked-twice-in-my-angular-appI suppose You are subscribing to action, so I get two subscriptions (and ErrorHandler is triggered twice).
If I change action execution to:
Action is still triggered (so You have to subscribe) but on success
this.changed.emit(id);
is never triggered.Edit:
this.obiektyActions.change(data)
=return this.store.dispatch(new ChangeDataAction(data));
Expected behavior
ErrorHandler should recive error info only once.
Minimal reproduction of the problem with instructions
https://stackblitz.com/edit/ngxs-error-throw?file=src/app/app.component.ts
What is the motivation / use case for changing the behavior?
Environment
The text was updated successfully, but these errors were encountered: