Skip to content

Commit 5b48912

Browse files
peterreiszbrandonroberts
authored andcommitted
fix(effects): resubscribe every time an error occurs (#2023) (#2026)
Closes #2023
1 parent 136c5eb commit 5b48912

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

modules/effects/spec/effect_sources.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,18 @@ describe('EffectSources', () => {
248248
it('should resubscribe on error by default', () => {
249249
class Eff {
250250
@Effect()
251-
b$ = hot('a--b--c--d').pipe(
251+
b$ = hot('a--e--b--e--c--e--d').pipe(
252252
map(v => {
253-
if (v == 'b') throw new Error('An Error');
253+
if (v == 'e') throw new Error('An Error');
254254
return v;
255255
})
256256
);
257257
}
258258

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

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

264264
expect(toActions(sources$)).toBeObservable(expected);
265265
});

modules/effects/src/effects_resolver.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ export function mergeEffects(
2424
? sourceInstance[propertyName]()
2525
: sourceInstance[propertyName];
2626

27+
const resubscribeInCaseOfError = (
28+
observable$: Observable<any>
29+
): Observable<any> =>
30+
observable$.pipe(
31+
catchError(error => {
32+
if (errorHandler) errorHandler.handleError(error);
33+
// Return observable that produces this particular effect
34+
return resubscribeInCaseOfError(observable$);
35+
})
36+
);
37+
2738
const resubscribable$ = resubscribeOnError
28-
? observable$.pipe(
29-
catchError(error => {
30-
if (errorHandler) errorHandler.handleError(error);
31-
// Return observable that produces this particular effect
32-
return observable$;
33-
})
34-
)
39+
? resubscribeInCaseOfError(observable$)
3540
: observable$;
3641

3742
if (dispatch === false) {

0 commit comments

Comments
 (0)