Skip to content

Commit b2e12ce

Browse files
committed
Unwind the exception causes with Java11Http#performConnect
Currently there is a generic exception caught for all kind of errors but as the execution is actually performed async this means that any exception is already wrapped in an ExecutionException holding the real cause. This unwinds the different causes that an happen (e.g. cancel, timeout, ...) and finally checks if this is an ExecutionException from the async operation-
1 parent 28753b9 commit b2e12ce

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/provider/filetransfer/httpclientjava/HttpClientRetrieveFileTransfer.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import java.util.Collections;
3737
import java.util.List;
3838
import java.util.Map;
39+
import java.util.concurrent.CancellationException;
3940
import java.util.concurrent.CompletableFuture;
41+
import java.util.concurrent.ExecutionException;
4042
import java.util.concurrent.TimeUnit;
4143
import java.util.zip.GZIPInputStream;
4244

@@ -1006,11 +1008,26 @@ private IStatus performConnect(IProgressMonitor monitor) {
10061008
int ticks = 1;
10071009
monitor.beginTask(getRemoteFileURL().toString() + Messages.HttpClientRetrieveFileTransfer_CONNECTING_TASK_NAME, ticks);
10081010
try {
1009-
if (monitor.isCanceled())
1010-
throw newUserCancelledException();
1011+
if (monitor.isCanceled()) {
1012+
setDoneCanceled();
1013+
return Status.CANCEL_STATUS;
1014+
}
10111015
httpResponse = httpClient.sendAsync(httpRequest, BodyHandlers.ofInputStream());
10121016
responseCode = httpResponse.get(getConnectTimeout(),TimeUnit.MILLISECONDS).statusCode();
1013-
} catch (final Exception e) {
1017+
} catch (InterruptedException e) {
1018+
Thread.currentThread().interrupt();
1019+
setDoneCanceled();
1020+
return Status.CANCEL_STATUS;
1021+
} catch (CancellationException e) {
1022+
setDoneCanceled();
1023+
return Status.CANCEL_STATUS;
1024+
} catch (Exception e) {
1025+
if (e instanceof ExecutionException) {
1026+
Throwable cause = ((ExecutionException) e).getCause();
1027+
if (cause instanceof Exception) {
1028+
e = (Exception) cause;
1029+
}
1030+
}
10141031
Trace.catching(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "performConnect", e); //$NON-NLS-1$
10151032
if (!isDone()) {
10161033
setDoneException(e);

0 commit comments

Comments
 (0)