DEV Community

loading...

Discussion on: Error Handling in RxJS — Building an RxJS PubSub

Collapse
anduser96 profile image
Andrei Gatej

Nice approach! Thanks for sharing.

As an alternative, couldn’t we achieve this by doing all this logic in the pipe()?

An error could be thrown inside a high order operator like mergeMap and handled later in the pipe.

In the handler, an object with an err property would be returned and inside the first cb of the subscribe function we can unsubscribe if an object with the err property is received.

I think this can be achieved without too much exertion. What do you think?

Collapse
deanius profile image
Dean Radcliffe Author

If you could write it up, then sure it could be achieved without much exertion :)

This is not to say that you can't do what you describe in raw RxJS, simply that may not be the most readable and approachable for beginners. And I have doubts as to whether a good default is to throw an unchecked error, interrupting the producer, and possibly crashing the process (if NodeJS)

Also, notice that in in my example there's no keeping around of a subscription object (a common point of confusion, and a place where reactive code becomes more imperative).

So please, show us the best way you think. And watch this awesome talk. It's not easy to do errors in RxJS that's for sure, I think there's plenty of room for innovation. youtube.com/watch?v=KlmABSriUbw