Skip to content

Commit

Permalink
docs(catch): minor changes to indention and wording
Browse files Browse the repository at this point in the history
  • Loading branch information
jayphelps authored Jan 27, 2017
1 parent 44a4f2d commit 8348549
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions src/operator/catch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,49 @@ import { subscribeToResult } from '../util/subscribeToResult';
/**
* Catches errors on the observable to be handled by returning a new observable or throwing an error.
*
* @example <caption>Returns a different Observable in case of error</caption>
* @example <caption>Continues with a different Observable when there's an error</caption>
*
* let primary$ = Observable.of(1, 2, 3, 4, 5);
* let secondary$ = Observable.of('I', 'II', 'III', 'IV', 'V');
*
* primary$
* .map(n => {
* if (n == 4)
* throw 'four!';
* return n;
* })
* .catch(err => secondary$)
* .subscribe(x => console.log(x)); // -> 1, 2, 3, I, II, III, IV, V
* Observable.of(1, 2, 3, 4, 5)
* .map(n => {
* if (n == 4) {
* throw 'four!';
* }
* return n;
* })
* .catch(err => Observable.of('I', 'II', 'III', 'IV', 'V'))
* .subscribe(x => console.log(x)); // -> 1, 2, 3, I, II, III, IV, V
*
* @example <caption>"Tries" the Observable again in case of error</caption>
* @example <caption>Retries the caught source Observable again in case of error, similar to retry() operator</caption>
*
* Observable.of(1, 2, 3, 4, 5)
* .map(n => {
* if (n === 4)
* throw 'four!';
* return n;
* })
* .catch((err, caught) => caught)
* .take(30)
* .subscribe(x => console.log(x)); // 1, 2, 3, 1, 2, 3, ...
* .map(n => {
* if (n === 4) {
* throw 'four!';
* }
* return n;
* })
* .catch((err, caught) => caught)
* .take(30)
* .subscribe(x => console.log(x));
* // 1, 2, 3, 1, 2, 3, ...
*
* @example <caption>Throws a new error when the source Observable throws an error</caption>
*
* Observable.of(1, 2, 3, 4, 5)
* .map(n => {
* if (n == 4)
* throw 'four!';
* return n;
* if (n == 4) {
* throw 'four!';
* }
* return n;
* })
* .catch(err => {
* throw 'error in source. Details: ' + err;
* })
* .catch(err => { throw 'error in source. Details: ' + err; })
* .subscribe(x => console.log(x),
* err => console.log(err)); -> 1, 2, 3, error in source. Details: four!
* .subscribe(
* x => console.log(x),
* err => console.log(err)
* );
* // 1, 2, 3, error in source. Details: four!
*
* @param {function} selector a function that takes as arguments `err`, which is the error, and `caught`, which
* is the source observable, in case you'd like to "retry" that observable by returning it again. Whatever observable
Expand Down

0 comments on commit 8348549

Please sign in to comment.