Most of the common RxJS operators was about transformation, combination or filtering, but this lesson was about a new categ Ory, error handling operators, and its most important operator:catch ().
Basic catch (Err = Observable):
varFoo = Rx.Observable.interval (500). zip (Rx.Observable.of (' A ', ' B ', ' C ', ' d ', 2), (x, y) = =y);varBar = Foo.map (x = =x.touppercase ());/*--a--b--c--d--2| (foo) map (touppercase)--a--b--c--d--# (bar) catch (# = ###|) --a--b--c--d--###|*/varresult = Bar.Catch(Error = Rx.Observable.of (' # # # '))); Result.subscribe (function(x) {Console.log (' next ' +x); }, function(ERR) {console.log (' error ' +err); }, function() {console.log (' done ')); },);
Retry with catch ((Error, outputobs) = Observable):
varFoo = Rx.Observable.interval (500). Map (()=math.random ());varBar = Foo.map (x = = { if(X < 0.5){ returnx; }Else{ Throw"Error, too large, try again" }});varresult =Bar.Catch(Error, Outputobs)= { returnOutputobs; }); Result.subscribe (function(x) {Console.log (' next ' +x); }, function(ERR) {console.log (' error ' +err); }, function() {console.log (' done ')); },);
Code Check whether the x is large than 0.5, if are then throw error, if not, then continue.
Bar$ catch the error and use ' Outputobs ' to repeat the action, so evenytime, it hits the error, it'll restart.
[RxJS] Error Handling Operator:catch