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 a syntax error, so JSON.parse won’t be able ...
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.