summaryrefslogtreecommitdiffstats
path: root/http-client
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2022-05-02 15:13:41 +0200
committerjonmv <venstad@gmail.com>2022-05-02 15:13:41 +0200
commit7116a75fb9af0f5ed3b3b6d80e8d2dfe2890c182 (patch)
treee0f3e371f92cd4caf3aba47d8a870f4b5a274462 /http-client
parent0b950e98b688edb6d67773c8ff536ba8db4c35d9 (diff)
Add status code to ResponseException
Diffstat (limited to 'http-client')
-rw-r--r--http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java10
1 files changed, 8 insertions, 2 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