11package io .a2a .client .http ;
22
3+ import static java .net .HttpURLConnection .HTTP_FORBIDDEN ;
4+ import static java .net .HttpURLConnection .HTTP_MULT_CHOICE ;
5+ import static java .net .HttpURLConnection .HTTP_OK ;
6+ import static java .net .HttpURLConnection .HTTP_UNAUTHORIZED ;
7+
38import java .io .IOException ;
9+ import java .net .HttpURLConnection ;
410import java .net .URI ;
511import java .net .http .HttpClient ;
612import java .net .http .HttpRequest ;
2228
2329public class JdkA2AHttpClient implements A2AHttpClient {
2430
25- private static final int HTTP_OK = 200 ;
26- private static final int HTTP_MULTIPLE_CHOICES = 300 ;
27- private static final int HTTP_UNAUTHORIZED = 401 ;
28- private static final int HTTP_FORBIDDEN = 403 ;
29-
3031 private final HttpClient httpClient ;
3132
3233 public JdkA2AHttpClient () {
@@ -186,7 +187,7 @@ public void onComplete() {
186187 if (!isSuccessStatus (response .statusCode ()) &&
187188 response .statusCode () != HTTP_UNAUTHORIZED &&
188189 response .statusCode () != HTTP_FORBIDDEN ) {
189- subscriber .onError (new IOException ("Request failed with status " + response .statusCode ()));
190+ subscriber .onError (new IOException ("Request failed with status " + response .statusCode () + ":" + response . body () ));
190191 }
191192 });
192193 }
@@ -294,7 +295,7 @@ public boolean success() {// Send the request and get the response
294295 }
295296
296297 static boolean success (HttpResponse <?> response ) {
297- return response .statusCode () >= HTTP_OK && response .statusCode () < HTTP_MULTIPLE_CHOICES ;
298+ return response .statusCode () >= HTTP_OK && response .statusCode () < HTTP_MULT_CHOICE ;
298299 }
299300
300301 @ Override
@@ -304,6 +305,6 @@ public String body() {
304305 }
305306
306307 private static boolean isSuccessStatus (int statusCode ) {
307- return statusCode >= HTTP_OK && statusCode < HTTP_MULTIPLE_CHOICES ;
308+ return statusCode >= HTTP_OK && statusCode < HTTP_MULT_CHOICE ;
308309 }
309310}
0 commit comments