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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.