-1

I need to be able to emit new values (next|error) with BehaviorSubject (preferably) to subscriber.

Basically I'd like to use BehaviorSubject as 2 separate streams for next and for error values, because from these errors it's possible to recover, eg. form input submitted and rejected from server, the new submitted value from the input could be accepted by server, therefore the subscriber should receive next val. eg. OK msg.

Now I have for each component a middle data service (based on this) extending some base service with BehaviorSubject for ok values and with Subject for error values. It seems to be working but I'm not sure how it will behave when I will have dozens of these services.

Is there a way to recover from error with BehaviorSubject or any method to comply proposed behavior?

Petr Marek
  • 1,381
  • 1
  • 15
  • 31

1 Answers1

1

If you dispatch an error on an Subject (or in your case BehaviorSubject, ReplaySubject) the Subject is essentially dead. In some cases it might make sense to add a .catch e.g. but even then: The Subject cannot be used any more to emit other data. So if you want to stick to two Subjects, use .next(...) on both and never manually use .error(...). Maybe additionally you want to have at this answer, it might be similar to your issue: https://stackoverflow.com/a/40823122/1518765

Community
  • 1
  • 1
olsn
  • 16,644
  • 6
  • 59
  • 65