Skip to content

Commit eb85fb3

Browse files
committedApr 19, 2017
DATAMONGO-1668 - Adopt changed Mono and Flux error handling API.
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.
1 parent ebc8c5d commit eb85fb3

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed
 

‎spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public <T> Flux<T> createFlux(ReactiveDatabaseCallback<T> callback) {
390390

391391
Assert.notNull(callback, "ReactiveDatabaseCallback must not be null!");
392392

393-
return Flux.defer(() -> callback.doInDB(getMongoDatabase())).onErrorResumeWith(translateFluxException());
393+
return Flux.defer(() -> callback.doInDB(getMongoDatabase())).onErrorMap(translateException());
394394
}
395395

396396
/**
@@ -404,7 +404,7 @@ public <T> Mono<T> createMono(final ReactiveDatabaseCallback<T> callback) {
404404

405405
Assert.notNull(callback, "ReactiveDatabaseCallback must not be null!");
406406

407-
return Mono.defer(() -> Mono.from(callback.doInDB(getMongoDatabase()))).otherwise(translateMonoException());
407+
return Mono.defer(() -> Mono.from(callback.doInDB(getMongoDatabase()))).onErrorMap(translateException());
408408
}
409409

410410
/**
@@ -422,7 +422,7 @@ public <T> Flux<T> createFlux(String collectionName, ReactiveCollectionCallback<
422422
Mono<MongoCollection<Document>> collectionPublisher = Mono
423423
.fromCallable(() -> getAndPrepareCollection(getMongoDatabase(), collectionName));
424424

425-
return collectionPublisher.flatMapMany(callback::doInCollection).onErrorResumeWith(translateFluxException());
425+
return collectionPublisher.flatMapMany(callback::doInCollection).onErrorMap(translateException());
426426
}
427427

428428
/**
@@ -442,7 +442,7 @@ public <T> Mono<T> createMono(String collectionName, ReactiveCollectionCallback<
442442
.fromCallable(() -> getAndPrepareCollection(getMongoDatabase(), collectionName));
443443

444444
return collectionPublisher.flatMap(collection -> Mono.from(callback.doInCollection(collection)))
445-
.otherwise(translateMonoException());
445+
.onErrorMap(translateException());
446446
}
447447

448448
/* (non-Javadoc)
@@ -1850,36 +1850,19 @@ private <T> T execute(MongoDatabaseCallback<T> action) {
18501850
}
18511851

18521852
/**
1853-
* Exception translation {@link Function} intended for {@link Flux#onErrorResumeWith(Function)} usage.
1853+
* Exception translation {@link Function} intended for {@link Flux#mapError(Function)}} usage.
18541854
*
18551855
* @return the exception translation {@link Function}
18561856
*/
1857-
private <T> Function<Throwable, Publisher<? extends T>> translateFluxException() {
1857+
private Function<Throwable, Throwable> translateException() {
18581858

18591859
return throwable -> {
18601860

18611861
if (throwable instanceof RuntimeException) {
1862-
return Flux.error(potentiallyConvertRuntimeException((RuntimeException) throwable, exceptionTranslator));
1862+
return potentiallyConvertRuntimeException((RuntimeException) throwable, exceptionTranslator);
18631863
}
18641864

1865-
return Flux.error(throwable);
1866-
};
1867-
}
1868-
1869-
/**
1870-
* Exception translation {@link Function} intended for {@link Mono#otherwise(Function)} usage.
1871-
*
1872-
* @return the exception translation {@link Function}
1873-
*/
1874-
private <T> Function<Throwable, Mono<? extends T>> translateMonoException() {
1875-
1876-
return throwable -> {
1877-
1878-
if (throwable instanceof RuntimeException) {
1879-
return Mono.error(potentiallyConvertRuntimeException((RuntimeException) throwable, exceptionTranslator));
1880-
}
1881-
1882-
return Mono.error(throwable);
1865+
return throwable;
18831866
};
18841867
}
18851868

0 commit comments

Comments
 (0)
Please sign in to comment.