Skip to content

Commit

Permalink
fix(effects): resubscribe every time an error occurs (#2023) (#2026)
Browse files Browse the repository at this point in the history
Closes #2023
  • Loading branch information
peterreisz authored and brandonroberts committed Jul 23, 2019
1 parent 136c5eb commit 5b48912
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions modules/effects/spec/effect_sources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,18 @@ describe('EffectSources', () => {
it('should resubscribe on error by default', () => {
class Eff {
@Effect()
b$ = hot('a--b--c--d').pipe(
b$ = hot('a--e--b--e--c--e--d').pipe(
map(v => {
if (v == 'b') throw new Error('An Error');
if (v == 'e') throw new Error('An Error');
return v;
})
);
}

const sources$ = of(new Eff());

// 👇 'b' is ignored.
const expected = cold('a-----c--d');
// 👇'e' is ignored.
const expected = cold('a-----b-----c-----d');

expect(toActions(sources$)).toBeObservable(expected);
});
Expand Down
19 changes: 12 additions & 7 deletions modules/effects/src/effects_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ 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
? observable$.pipe(
catchError(error => {
if (errorHandler) errorHandler.handleError(error);
// Return observable that produces this particular effect
return observable$;
})
)
? resubscribeInCaseOfError(observable$)
: observable$;

if (dispatch === false) {
Expand Down

0 comments on commit 5b48912

Please sign in to comment.