1

I want my action stream to continue even if there is an error. There for I created a catch and replace observer which replace the error call with an empty observable. Now when there is an error the observable completes its operation immediately although there is a replacement.

Is there a way yo show the error but let the action stream continue emitting actions?

The catch and replace code is in my stackblitz

Udi Mazor
  • 1,646
  • 2
  • 15
  • 30
  • This is the expected behavior. `catchError` replaces the original observable with the one it has returned. What are you trying to achieve? – sneas Oct 03 '19 at 10:43
  • Please, have a look at this: https://stackoverflow.com/questions/43623868/rxjs-how-to-ignore-an-error-with-catch-and-keep-going – Goga Koreli Oct 03 '19 at 10:46

2 Answers2

1

Few approach to keep a stream from completing

Contains your operation in inner Observable:

source.pipe(switchMap(x=>
     defer(()=>.... some operation that might throw).pipe(catchError(e=>of(e))))

Using repeat() or repeatWhen()

source.pipe(catchError(e=>of(e)),repeat())

Using retry() - using it with caution, most of the time error will not go away and you end up infinite loop

source.pipe(retry())
Fan Cheung
  • 10,745
  • 3
  • 17
  • 39
0

According to the official docs of rxjs: (https://rxjs-dev.firebaseapp.com/guide/observable)

In an Observable Execution, zero to infinite Next notifications may be delivered. If either an Error or Complete notification is delivered, then nothing else can be delivered afterwards.

You can go for retry operator or change your Observable to be of type Observable<Data | Error>, distinguish those emissions and handle respectfully.

    setTimeout(() => {
      observer.next({data: 'Some data'});
    }, 7000);

    setTimeout(() => {
      observer.next({error: 'Some error message'});
    }, 8000);
Yevhenii Dovhaniuk
  • 1,073
  • 5
  • 11