Reactive Error Handling
Learn to handle errors that can be thrown in the data stream and the subscribe callback.
We'll cover the following...
Error handling in RxJS overview
In this lesson, we will go through a very important concept: error handling in reactive streams.
In order to understand error handling in RxJS, you must first understand that an error can be thrown in the stream only once. This means that a stream can either complete successfully by emitting all the values or by throwing an error.
It is very important to understand that after an error is thrown inside the stream, it will not emit any other values.
RxJS provides a very simple mechanism to deal with errors: Every subscriber can provide three callbacks to the Observable:
- Success callback
- Error callback
- Finally callback
observable.subscribe(value => {// VALUE EMITTED SUCCESSFULLY},error => {// AN ERROR OCCURED DURING EMISSION},() => {// FINALLY BLOCK, EXECUTES ALWASY})
These three callbacks are enough to deal with errors in most of the cases. However, this approach for error handling is very limited. If the second callback is invoked, it means that an error was thrown somewhere down the data stream. This leads to several questions that need to be answered, including: ...