From eb85fb3a14233be2dd979825f55fe8e8b67cff22 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 19 Apr 2017 14:54:14 +0200 Subject: [PATCH] DATAMONGO-1668 - Adopt changed Mono and Flux error handling API. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace Flux/Mono.onErrorResumeWith(…) with Flux/Mono.onErrorMap(…) and turn translateException into a method returning a mapping function instead of a reactive type emitting the mapped exception. --- .../mongodb/core/ReactiveMongoTemplate.java | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java index 870152ba1..4aaec24b6 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java @@ -390,7 +390,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati Assert.notNull(callback, "ReactiveDatabaseCallback must not be null!"); - return Flux.defer(() -> callback.doInDB(getMongoDatabase())).onErrorResumeWith(translateFluxException()); + return Flux.defer(() -> callback.doInDB(getMongoDatabase())).onErrorMap(translateException()); } /** @@ -404,7 +404,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati Assert.notNull(callback, "ReactiveDatabaseCallback must not be null!"); - return Mono.defer(() -> Mono.from(callback.doInDB(getMongoDatabase()))).otherwise(translateMonoException()); + return Mono.defer(() -> Mono.from(callback.doInDB(getMongoDatabase()))).onErrorMap(translateException()); } /** @@ -422,7 +422,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati Mono> collectionPublisher = Mono .fromCallable(() -> getAndPrepareCollection(getMongoDatabase(), collectionName)); - return collectionPublisher.flatMapMany(callback::doInCollection).onErrorResumeWith(translateFluxException()); + return collectionPublisher.flatMapMany(callback::doInCollection).onErrorMap(translateException()); } /** @@ -442,7 +442,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati .fromCallable(() -> getAndPrepareCollection(getMongoDatabase(), collectionName)); return collectionPublisher.flatMap(collection -> Mono.from(callback.doInCollection(collection))) - .otherwise(translateMonoException()); + .onErrorMap(translateException()); } /* (non-Javadoc) @@ -1850,36 +1850,19 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati } /** - * Exception translation {@link Function} intended for {@link Flux#onErrorResumeWith(Function)} usage. + * Exception translation {@link Function} intended for {@link Flux#mapError(Function)}} usage. * * @return the exception translation {@link Function} */ - private Function> translateFluxException() { + private Function translateException() { return throwable -> { if (throwable instanceof RuntimeException) { - return Flux.error(potentiallyConvertRuntimeException((RuntimeException) throwable, exceptionTranslator)); + return potentiallyConvertRuntimeException((RuntimeException) throwable, exceptionTranslator); } - return Flux.error(throwable); - }; - } - - /** - * Exception translation {@link Function} intended for {@link Mono#otherwise(Function)} usage. - * - * @return the exception translation {@link Function} - */ - private Function> translateMonoException() { - - return throwable -> { - - if (throwable instanceof RuntimeException) { - return Mono.error(potentiallyConvertRuntimeException((RuntimeException) throwable, exceptionTranslator)); - } - - return Mono.error(throwable); + return throwable; }; }