Skip to content

Commit

Permalink
Merge pull request #93 from laeubi/unwind_execpetion_java_http
Browse files Browse the repository at this point in the history
Unwind the exception causes with Java11Http#performConnect
  • Loading branch information
scottslewis authored Dec 29, 2024
2 parents efe7c06 + b2e12ce commit fa13d49
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;

Expand Down Expand Up @@ -1006,11 +1008,26 @@ private IStatus performConnect(IProgressMonitor monitor) {
int ticks = 1;
monitor.beginTask(getRemoteFileURL().toString() + Messages.HttpClientRetrieveFileTransfer_CONNECTING_TASK_NAME, ticks);
try {
if (monitor.isCanceled())
throw newUserCancelledException();
if (monitor.isCanceled()) {
setDoneCanceled();
return Status.CANCEL_STATUS;
}
httpResponse = httpClient.sendAsync(httpRequest, BodyHandlers.ofInputStream());
responseCode = httpResponse.get(getConnectTimeout(),TimeUnit.MILLISECONDS).statusCode();
} catch (final Exception e) {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
setDoneCanceled();
return Status.CANCEL_STATUS;
} catch (CancellationException e) {
setDoneCanceled();
return Status.CANCEL_STATUS;
} catch (Exception e) {
if (e instanceof ExecutionException) {
Throwable cause = ((ExecutionException) e).getCause();
if (cause instanceof Exception) {
e = (Exception) cause;
}
}
Trace.catching(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "performConnect", e); //$NON-NLS-1$
if (!isDone()) {
setDoneException(e);
Expand Down

0 comments on commit fa13d49

Please sign in to comment.