diff options
author | jonmv <venstad@gmail.com> | 2022-05-02 15:13:41 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-05-02 15:13:41 +0200 |
commit | 7116a75fb9af0f5ed3b3b6d80e8d2dfe2890c182 (patch) | |
tree | e0f3e371f92cd4caf3aba47d8a870f4b5a274462 | |
parent | 0b950e98b688edb6d67773c8ff536ba8db4c35d9 (diff) |
Add status code to ResponseException
3 files changed, 12 insertions, 9 deletions
diff --git a/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java b/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java index eeb9c353f64..ea8328ed793 100644 --- a/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java +++ b/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java @@ -226,7 +226,8 @@ public interface HttpClient extends Closeable { @Override default RuntimeException toException(int statusCode, byte[] body, ClassicHttpRequest request) { - return new ResponseException(request + " failed with status " + statusCode + " and body '" + new String(body, UTF_8) + "'"); + return new ResponseException(statusCode, + request + " failed with status " + statusCode + " and body '" + new String(body, UTF_8) + "'"); } } @@ -297,10 +298,15 @@ public interface HttpClient extends Closeable { /** An exception due to server error, a bad request, or similar, which resulted in a non-OK HTTP response. */ class ResponseException extends RuntimeException { - public ResponseException(String message) { + private final int statusCode; + + public ResponseException(int statusCode, String message) { super(message); + this.statusCode = statusCode; } + public int statusCode() { return statusCode; } + } }
\ No newline at end of file diff --git a/http-utils/src/main/java/ai/vespa/util/http/hc5/DefaultHttpClientBuilder.java b/http-utils/src/main/java/ai/vespa/util/http/hc5/DefaultHttpClientBuilder.java index 6adbcbf068c..8866d67fd60 100644 --- a/http-utils/src/main/java/ai/vespa/util/http/hc5/DefaultHttpClientBuilder.java +++ b/http-utils/src/main/java/ai/vespa/util/http/hc5/DefaultHttpClientBuilder.java @@ -28,12 +28,8 @@ public class DefaultHttpClientBuilder { private DefaultHttpClientBuilder() { } - public static HttpClientBuilder create(SSLContext sslContext, String userAgent) { - return create(() -> sslContext, new DefaultHostnameVerifier(), userAgent); - } - - public static HttpClientBuilder create(SSLContext sslContext, HostnameVerifier verifier, String userAgent) { - return create(() -> sslContext, verifier, userAgent); + public static HttpClientBuilder create(Supplier<SSLContext> sslContext, String userAgent) { + return create(sslContext, new DefaultHostnameVerifier(), userAgent); } /** Creates an HTTP client builder with the given SSL context, and using the provided timeouts for requests where config is not overridden. */ diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientImpl.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientImpl.java index 37a690bd2bd..28ba259d2ae 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientImpl.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientImpl.java @@ -181,7 +181,8 @@ public class ClusterControllerClientImpl implements ClusterControllerClient { Inspector root = SlimeUtils.jsonToSlime(body).get(); String detail = root.field("message").valid() ? root.field("message").asString() : new String(body, UTF_8); - return new ResponseException("got status code " + statusCode + " for " + request + (detail.isBlank() ? "" : ": " + detail)); + return new ResponseException(statusCode, + "got status code " + statusCode + " for " + request + (detail.isBlank() ? "" : ": " + detail)); } }; |