How to stop flow when specific error occur in project reactor?

51 views Asked by At

I've an external API call that may return an HTTP error, in some cases I want to stop the flow and on other to let it continue depending on the status, how can I "filter" a specific error?

Here's the code:

Mono<Void> call() {
    service.find()
        .filter{}
        .flatMap {
            otherService.find()
                .doOnError {
                    if (it instanceof NotFound) {
                        // do not propagate the error and stop
                    }
                    // propagate the error
                }
                .flatMap{}.then()
        }.then()
}

I've tried to use OnErrorContinue but the error is never matched:

.onErrorContinue({ it instanceof NotFound }, (err) -> {
    log.info(err.message)
})
1

There are 1 answers

0
Mike W On

Try the following...

.onErrorContinue( NotFound.class, (throwable, o) -> {
    log.info(throwable.message)
})