Skip to content

Commit 48906af

Browse files
committed
Polishing JettyClientHttpRequestFactory
1 parent ef4d935 commit 48906af

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

spring-web/src/main/java/org/springframework/http/client/JettyClientHttpRequest.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.io.OutputStream;
21+
import java.io.UncheckedIOException;
2122
import java.net.URI;
2223
import java.util.concurrent.ExecutionException;
2324
import java.util.concurrent.TimeUnit;
@@ -98,8 +99,24 @@ protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body
9899
Thread.currentThread().interrupt();
99100
throw new IOException("Request was interrupted: " + ex.getMessage(), ex);
100101
}
101-
catch (TimeoutException | ExecutionException ex) {
102-
throw new IOException("Could not send request: " + ex.getMessage(), ex);
102+
catch (ExecutionException ex) {
103+
Throwable cause = ex.getCause();
104+
105+
if (cause instanceof UncheckedIOException uioEx) {
106+
throw uioEx.getCause();
107+
}
108+
if (cause instanceof RuntimeException rtEx) {
109+
throw rtEx;
110+
}
111+
else if (cause instanceof IOException ioEx) {
112+
throw ioEx;
113+
}
114+
else {
115+
throw new IOException(cause.getMessage(), cause);
116+
}
117+
}
118+
catch (TimeoutException ex) {
119+
throw new IOException("Request timed out: " + ex.getMessage(), ex);
103120
}
104121
}
105122
}

0 commit comments

Comments
 (0)