From 637580d9b1c20d9e1d4412738657b61836b4f365 Mon Sep 17 00:00:00 2001 From: Matt Farmer Date: Wed, 5 Jul 2017 16:05:23 -0400 Subject: [PATCH] Unwrap execution exceptions if they have a cause The execution exception itself isn't a terribly useful measure of what actually happened under the hood. As a result, #111 proposed unwrapping them before finishing the future. I'm still not sure what I think of this idea, but it was straightforward enough to implement and we have some time before 0.14.x is declared final. --- core/src/main/scala/execution.scala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/scala/execution.scala b/core/src/main/scala/execution.scala index ddf0708a..85b72d7e 100644 --- a/core/src/main/scala/execution.scala +++ b/core/src/main/scala/execution.scala @@ -114,11 +114,11 @@ trait HttpExecutor { (implicit executor: ExecutionContext): Future[T] = apply(pair._1, pair._2) - def apply[T] - (request: Request, handler: AsyncHandler[T]) - (implicit executor: ExecutionContext): Future[T] = { + def apply[T](request: Request, handler: AsyncHandler[T]) + (implicit executor: ExecutionContext): Future[T] = { val lfut = client.executeRequest(request, handler) val promise = scala.concurrent.Promise[T]() + lfut.addListener( () => promise.complete(Try(lfut.get())), new juc.Executor { @@ -127,7 +127,11 @@ trait HttpExecutor { } } ) - promise.future + + promise.future.recoverWith { + case executionEx: juc.ExecutionException if executionEx.getCause() != null => + Future.failed(executionEx.getCause()) + } } def shutdown() = {