Exception in failed CompletionStage is always wrapped in CompletionException
#1 267 ouverte le 5 juil. 2017
Métriques du dépôt
- Stars
- (1 311 étoiles)
- Métriques de merge PR
- (Merge moyen 1j 10h) (2 PRs mergées en 30 j)
Description
When using the completeOKWithFutureString or completeOKWithFuture directives from the javadsl, the exception in a failed CompletionStage is always wrapped in a CompletionException.
This is unfortunate, as you end up writing ExceptionHandlers like this:
ExceptionHandler exceptionHandler = ExceptionHandler.newBuilder()
.match(CompletionException.class, e -> {
if (e.getCause() instanceof IllegalStateException) return complete(StatusCodes.NOT_FOUND);
// Etc.
else return complete(StatusCodes.INTERNAL_SERVER_ERROR);
})
.build();
The CompletionException doesn't appear to contain any useful information (not in the stacktrace either), perhaps we should consider unwrapping it in akka-http - though that would be a breaking change. Perhaps we could deprecate completeOKWithFuture(String) and add completeOKWithCompletionStage(String) that unwraps, as that's the native terminology anyway?