Handling Errors
Remember when we talked about the three methods we can call on an Observer? (If you need a refresher, refer back to âThe Observer Interfaceâ.) Weâre familiar with next and complete, but we havenât yet used error; it is the key to effectively handling errors in Observable sequences.
To see how it works, weâll write a simple function to take an array of JSON strings and return an Observable that emits the objects parsed from those strings, using JSON.parse:
â | âimportâ { Observable } âfromâ â"rxjs"â; |
â | âfunctionâ getJSON(arr) { |
â | âreturnâ Observable.âfromâ(arr).map(JSON.parse); |
â | } |
Weâll pass an array with three JSON strings to getJSON, in which the second string in the array contains ...
Get Reactive Programming with RxJS 5 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.