The problem is how the completed exception CompletableFuturehandles the exception in subsequent steps.
As stated in CompletableFuture javadoc
[..], () , , , , CompletionException . [..]
thenApply CompletionStage, CompletionException UserNotFoundException: (
, . Zalando : Async CompletableFuture append errors
, CompletableFuture Spring.
a CompletableFuture<T> a DeferredResult<T>. .
public class DeferredResults {
private DeferredResults() {}
public static <T> DeferredResult<T> from(final CompletableFuture<T> future) {
final DeferredResult<T> deferred = new DeferredResult<>();
future.thenAccept(deferred::setResult);
future.exceptionally(ex -> {
if (ex instanceof CompletionException) {
deferred.setErrorResult(ex.getCause());
} else {
deferred.setErrorResult(ex);
}
return null;
});
return deferred;
}
}
, .
@GetMapping("/{id}/address")
public DeferredResult<Address> getAddress(@PathVariable String id) {
return DeferredResults.from(service.findById(id).thenApply(User::getAddress));
}
, Spring CompletableFuture , .
, .