Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(effects): resubscribe every time an error occurs #2165

Merged
merged 3 commits into from
Oct 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions modules/effects/src/effects_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,8 @@ export function mergeEffects(
? sourceInstance[propertyName]()
: sourceInstance[propertyName];

const resubscribeInCaseOfError = (
observable$: Observable<any>
): Observable<any> =>
observable$.pipe(
catchError(error => {
if (errorHandler) errorHandler.handleError(error);
// Return observable that produces this particular effect
return resubscribeInCaseOfError(observable$);
})
);

const resubscribable$ = resubscribeOnError
? resubscribeInCaseOfError(observable$)
? resubscribeInCaseOfError(observable$, errorHandler)
: observable$;

if (dispatch === false) {
Expand All @@ -61,3 +50,19 @@ export function mergeEffects(

return merge(...observables$);
}

/**
* @internal
*/
export function resubscribeInCaseOfError<T extends Action = Action>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to export it, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it also doesn't need the @internal comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is = Action needed? I think just extending Action is fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it isn't needed. Thanks for the review 👍

observable$: Observable<T>,
errorHandler?: ErrorHandler
): Observable<T> {
return observable$.pipe(
catchError(error => {
if (errorHandler) errorHandler.handleError(error);
// Return observable that produces this particular effect
return resubscribeInCaseOfError(observable$, errorHandler);
})
);
}