The doOnError hook

We discussed life cycle hooks in Chapter 2The Publisher and Subscriber APIs in a Reactor. These can be used to configure callbacks for every life cycle event. Reactor provides the life cycle error callback hook to configure the error handler. The doOnError hook allows us to consume an error and perform the intended function. If we have configured the doOnError hook along with the error callback, then both will be invoked simultaneously by Reactor. The following code shows this:

    @Test    public void testDoError() {        // Removed for brevity        fibonacciGenerator                .doOnError(System.out::println)                .subscribe(System.out::println, e -> e.printStackTrace());    }

The preceding code does the following:

  1. Configures the println function in ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.