Rxjs handle error in separate pipeline and merge

Viewed 493

I want to split Observable into two streams of Observable on error

catch operator can convert error into valid by returning an observable or propagate error either by throwing or returning Observable.throw

partition operator only processes valid values, no errors pass through this

what I need is split Observable into two Observables and process then differently and merge them as seen in below diagram

enter image description here

1 Answers

Pattern like this might fit your use case

step1
  .map((data)=>{data:data})
  .catch(()=>Observable.of({error:'error'})
  .flatMap((res)=>{
    //process A and B should return observable
    if(res.data) return processA(res)
    return processB(res)
  })
  .map(res=>{
  //do your merged processing here 
  })
  .subscribe()

Related