RxJS catchError() Error Handling OperatorRxJS catchError() operator is an error-handling operator used to handle and take care of catching errors on the source observable by returning a new observable or an error. In other words, we can say that the RxJS catchError() operator catches errors on the observable and gracefully handles errors in an observable sequence. It handles the errors by returning a new observable or throwing an error. Syntax:Following is the syntax of the RxJS catchError() error handling operator: Or Parameter Explanation
Return valueThe RxJS catchError() operator returns an observable that originates from either the source or the observable returned by the catch selector function or selector_func. Let us see some examples of the RxJS catchError() operator to understand it clearly. Example 1 (Catching error from observable)Output: After executing the above example, you will see the following result: Example 1 (Observable when there is an error)Output: After executing the above example, you will see the following result: Example 2Output: After executing the above example, you will see the following result: Example 3 (Catching rejected promise)Output: After executing the above example, you will see the following result:
Next TopicRxJS Operators
|