Copilot commented on code in PR #7072:
URL: https://github.com/apache/shenyu/pull/7072#discussion_r4032852309
##########
shenyu-sdk/shenyu-sdk-httpclient/src/main/java/org/apache/shenyu/sdk/httpclient/HttpShenyuSdkClient.java:
##########
@@ -162,14 +164,33 @@ public void cancelled() {
LOG.debug("HttpResponse cancelled.");
}
});
+ HttpResponse response = waitForResponse(execute);
+ return new ShenyuResponse(response.getStatusLine().getStatusCode(),
response.getStatusLine().getReasonPhrase(),
+
Arrays.stream(response.getAllHeaders()).collect(Collectors.groupingBy(Header::getName,
HashMap::new,
+ Collectors.mapping(Header::getValue,
Collectors.toCollection(LinkedList::new)))),
+ EntityUtils.toString(response.getEntity(),
StandardCharsets.UTF_8), request);
+ }
+
+ private HttpResponse waitForResponse(final Future<HttpResponse>
responseFuture) throws IOException {
try {
- HttpResponse response = execute.get();
- return new
ShenyuResponse(response.getStatusLine().getStatusCode(),
response.getStatusLine().getReasonPhrase(),
-
Arrays.stream(response.getAllHeaders()).collect(Collectors.groupingBy(Header::getName,
HashMap::new,
- Collectors.mapping(Header::getValue,
Collectors.toCollection(LinkedList::new)))),
- EntityUtils.toString(response.getEntity(),
StandardCharsets.UTF_8), request);
- } catch (Exception e) {
- throw new ShenyuException(e);
+ return responseFuture.get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IOException("Interrupted while waiting for the HTTP
response", e);
+ } catch (ExecutionException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof IOException) {
+ throw (IOException) cause;
+ }
+ if (cause instanceof RuntimeException) {
+ throw (RuntimeException) cause;
+ }
+ if (cause instanceof Error) {
+ throw (Error) cause;
+ }
+ throw new IOException("HTTP request failed", cause);
+ } catch (CancellationException e) {
+ throw new IOException("HTTP request was cancelled", e);
Review Comment:
The new cancellation-to-`IOException` behavior has no regression coverage,
although the adjacent transport and interruption branches are tested. Add a
case where `Future.get()` throws `CancellationException` and verify that
`doRequest` exposes it as an `IOException`, so this retry-path contract cannot
regress.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]