1

I am using observables and the rxJS library .

I create my observable as follows:

this.validate$ = new Observable(observer =>
this.validateObserver = observer).share();

I then push objects onto this as follows:

this.validateObserver.next(responseJson);

If there is an error in what i am fetching, i pass on the error as follows:

this.validateObserver.error(this.setErrorMessage(filter));

I subscribe to this as follows, from a different class :

this.uploader.validate$.subscribe(
      result => {
        console.log('result triggered');
      },
      error => {
        console.log('error triggered');
      }

However i want my subscriber to keep listening after it receives and error instead of terminating listening as it does currently.

Can someone help with how I would be able to resume after processing the error ?

shahharsh2603
  • 73
  • 2
  • 9
  • I think the answers to this question http://stackoverflow.com/questions/35326689/how-to-catch-exception-correctly-from-http-request should help – Günter Zöchbauer Mar 02 '16 at 20:04

2 Answers2

0

It's more obvious in the rxJava documentation found here but onError is meant to terminate the observable. You are not supposed to call onNext or onCompleted after notifying an error.

Here is what the docs say about onError:

Notifies the Observer that the Observable has experienced an error condition.

If the Observable calls this method, it will not thereafter call onNext(T) or onCompleted().


One way to accomplish what you want is to create another observable for the errors and call onNext for that observable when you come across your error condition.

Gloopy
  • 37,767
  • 15
  • 103
  • 71
0

You need to use doOnError

Check here http://xgrommx.github.io/rx-book/content/observable/observable_instance_methods/doonerror.html

paul
  • 12,873
  • 23
  • 91
  • 153