forked from airlift/airlift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly catch errors thrown by request handlers
If the request handlers throw any exceptions, the call to JettyHttpClient would previously fail with an inline exception, rather than returning a failed future. This is fixed here.
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
http-client/src/main/java/io/airlift/http/client/jetty/FailedHttpResponseFuture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.airlift.http.client.jetty; | ||
|
||
import com.google.common.util.concurrent.ListenableFuture; | ||
import io.airlift.http.client.HttpClient; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import static com.google.common.util.concurrent.Futures.immediateFailedFuture; | ||
|
||
public class FailedHttpResponseFuture<T> | ||
implements HttpClient.HttpResponseFuture<T> | ||
{ | ||
private final ListenableFuture<T> delegate; | ||
|
||
public FailedHttpResponseFuture(Throwable throwable) | ||
{ | ||
this.delegate = immediateFailedFuture(throwable); | ||
} | ||
|
||
@Override | ||
public String getState() | ||
{ | ||
return "FAILED"; | ||
} | ||
|
||
@Override | ||
public void addListener(Runnable listener, Executor executor) | ||
{ | ||
delegate.addListener(listener, executor); | ||
} | ||
|
||
@Override | ||
public boolean cancel(boolean mayInterruptIfRunning) | ||
{ | ||
return delegate.cancel(mayInterruptIfRunning); | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() | ||
{ | ||
return delegate.isCancelled(); | ||
} | ||
|
||
@Override | ||
public boolean isDone() | ||
{ | ||
return delegate.isDone(); | ||
} | ||
|
||
@Override | ||
public T get() | ||
throws InterruptedException, ExecutionException | ||
{ | ||
return delegate.get(); | ||
} | ||
|
||
@Override | ||
public T get(long timeout, TimeUnit unit) | ||
throws InterruptedException, ExecutionException, TimeoutException | ||
{ | ||
return delegate.get(timeout, unit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters