When observing errored Actions it would be useful to catch the error that made the action fail. Can the error be provided?
* ngxs: 3.0.1
* @angular/core: 6.0.3
Error available within ofActionErrored
This would be a really good idea.
Use case: login which can fail for multiple reason, so there could be multiple throw statement inside a single action, each with a different message.
When listening to the Action stream it's necessary to understand _which_ error are we dealing with.
Ex.
this.actions.pipe(
ofActionErrored(Login)
).subscribe((action, error) => console.log(error));
I checked the code, it seems to me that this is actually just a matter of exposing the full ActionContext instead of mapping it to just the action, changing this
removing altogether mapAction.
Or, if you _really_ want to hide the status label, it's just a matter of changing the mapping there
maybe like
function mapAction() {
return map(({action, error}: ActionContext) => { action, error );
}
@markwhitfeld shall I make a PR?
This would be very useful - any chance it'll make it in the next release?
@splincode Any chance you could have a look at how we could do this without introducing a breaking change?
@markwhitfeld I will try to see soon
This will be achievable using the ofActionCompleted pipe when v3.4 is released.
Use the @dev version now to try it out.
See this comment for the signature of what is returned by this pipe: https://github.com/ngxs/store/issues/710#issuecomment-447647487
This will be in the docs once PR #726 is merged
馃帀馃帀
Even though, the simplicity of returning the error via ofActionErrored would be the best.
If you consider this to be a breaking change, can we hope to see it in version 4.0 maybe?
I'm using the dev version (future 3.4) and I'm using a custom operator to mimic the ofActionErroed:
export const ofActionErroredWithError = (action: object) =>
(source: Observable<ActionContext<typeof action>>) =>
source.pipe(
ofActionCompleted(action),
filter((completion: ActionCompletion) => !!completion.result.error),
map(completion => ({ action: completion.action, error: completion.result.error}))
);
Unfortunately ofAction() does not expose the ActionContext instance, otherwise, it could be a solution for versions pre 3.4.
Most helpful comment
I checked the code, it seems to me that this is actually just a matter of exposing the full
ActionContextinstead of mapping it to just the action, changing thishttps://github.com/ngxs/store/blob/56660422c543f61aa7c0f3ee55e37f6bff8fc3b8/packages/store/src/operators/of-action.ts#L57
removing altogether
mapAction.Or, if you _really_ want to hide the status label, it's just a matter of changing the mapping there
https://github.com/ngxs/store/blob/56660422c543f61aa7c0f3ee55e37f6bff8fc3b8/packages/store/src/operators/of-action.ts#L69-L71
maybe like
@markwhitfeld shall I make a PR?