Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

catchError.d.ts 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { Observable } from '../Observable';
  2. import { ObservableInput, OperatorFunction, MonoTypeOperatorFunction } from '../types';
  3. /**
  4. * Catches errors on the observable to be handled by returning a new observable or throwing an error.
  5. *
  6. * ![](catch.png)
  7. *
  8. * ## Examples
  9. * Continues with a different Observable when there's an error
  10. *
  11. * ```javascript
  12. * of(1, 2, 3, 4, 5).pipe(
  13. * map(n => {
  14. * if (n == 4) {
  15. * throw 'four!';
  16. * }
  17. * return n;
  18. * }),
  19. * catchError(err => of('I', 'II', 'III', 'IV', 'V')),
  20. * )
  21. * .subscribe(x => console.log(x));
  22. * // 1, 2, 3, I, II, III, IV, V
  23. * ```
  24. *
  25. * Retries the caught source Observable again in case of error, similar to retry() operator
  26. *
  27. * ```javascript
  28. * of(1, 2, 3, 4, 5).pipe(
  29. * map(n => {
  30. * if (n === 4) {
  31. * throw 'four!';
  32. * }
  33. * return n;
  34. * }),
  35. * catchError((err, caught) => caught),
  36. * take(30),
  37. * )
  38. * .subscribe(x => console.log(x));
  39. * // 1, 2, 3, 1, 2, 3, ...
  40. * ```
  41. *
  42. * Throws a new error when the source Observable throws an error
  43. *
  44. * ```javascript
  45. * of(1, 2, 3, 4, 5).pipe(
  46. * map(n => {
  47. * if (n == 4) {
  48. * throw 'four!';
  49. * }
  50. * return n;
  51. * }),
  52. * catchError(err => {
  53. * throw 'error in source. Details: ' + err;
  54. * }),
  55. * )
  56. * .subscribe(
  57. * x => console.log(x),
  58. * err => console.log(err)
  59. * );
  60. * // 1, 2, 3, error in source. Details: four!
  61. * ```
  62. *
  63. * @param {function} selector a function that takes as arguments `err`, which is the error, and `caught`, which
  64. * is the source observable, in case you'd like to "retry" that observable by returning it again. Whatever observable
  65. * is returned by the `selector` will be used to continue the observable chain.
  66. * @return {Observable} An observable that originates from either the source or the observable returned by the
  67. * catch `selector` function.
  68. * @name catchError
  69. */
  70. export declare function catchError<T>(selector: (err: any, caught: Observable<T>) => never): MonoTypeOperatorFunction<T>;
  71. export declare function catchError<T, R>(selector: (err: any, caught: Observable<T>) => ObservableInput<R>): OperatorFunction<T, T | R>;