The onErrorReturn operator

Reactor provides the OnErrorReturn operator to provide a fallback value in the event of an error. As a result of the fallback, the original error event is not propagated to the error callback. The event processing continues by using the event handler, as follows:

    @Test    public void testErrorReturn() {        Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,                Long>of(0L, 1L), (state, sink) -> {            if (state.getT1() < 0)                sink.error(new RuntimeException("Value out of bounds"));            else                sink.next(state.getT1());            return Tuples.of(state.getT2(), state.getT1() + state.getT2());        });        fibonacciGenerator                .onErrorReturn(0L)                .subscribe(System.out::println);    }

In the preceding code, the following applies:

  1. The onErrorReturn ...

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.