Skip to content

Commit

Permalink
Unwrap execution exceptions if they have a cause
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
farmdawgnation committed Jul 5, 2017
1 parent be01673 commit 637580d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/src/main/scala/execution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() = {
Expand Down

0 comments on commit 637580d

Please sign in to comment.