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

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