Skip to content

Commit

Permalink
add ResponseException#status
Browse files Browse the repository at this point in the history
this allows accessing the HTTP status code of the response when an API
returns a `ResponseException`. this was not possible through
`getResponse` since `Response` itself is package-private and thus its
members (even though they are marked as `public`) are not accessible to
external consumers.

as there's no test coverage for `ResponseException` i haven't added any
for the new API either, as it is a trivial API and it was unclear how
adding test coverage for it would fit into the existing test coverage.

solves #749

Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
  • Loading branch information
rursprung committed Dec 4, 2023
1 parent 9213138 commit dbd2033
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static String buildMessage(Response response) throws IOException {
response.getRequestLine().getMethod(),
response.getHost(),
response.getRequestLine().getUri(),
response.getStatusLine().toString()
response.getStatusLine()
);

if (response.hasWarnings()) {
Expand All @@ -73,7 +73,7 @@ static String buildMessage(Response response) throws IOException {

HttpEntity entity = response.getEntity();
if (entity != null) {
if (entity.isRepeatable() == false) {
if (!entity.isRepeatable()) {
entity = new BufferedHttpEntity(entity);
response.getHttpResponse().setEntity(entity);
}
Expand All @@ -92,4 +92,12 @@ static String buildMessage(Response response) throws IOException {
public Response getResponse() {
return response;
}

/**
* Status code returned by Elasticsearch. Shortcut for
* {@code response().status()}.
*/
public int status() {
return this.response.getStatusLine().getStatusCode();
}
}

0 comments on commit dbd2033

Please sign in to comment.