-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. solves #749 Signed-off-by: Ralph Ursprung <[email protected]> (cherry picked from commit 863518c)
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ient/src/test/java/org/opensearch/client/transport/httpclient5/ResponseExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.opensearch.client.transport.httpclient5; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import java.io.IOException; | ||
import org.apache.hc.core5.http.HttpHost; | ||
import org.apache.hc.core5.http.HttpStatus; | ||
import org.apache.hc.core5.http.HttpVersion; | ||
import org.apache.hc.core5.http.message.BasicClassicHttpResponse; | ||
import org.apache.hc.core5.http.message.RequestLine; | ||
import org.junit.Test; | ||
|
||
public class ResponseExceptionTest { | ||
|
||
@Test | ||
public void testStatus() throws IOException { | ||
final var response = this.buildResponseException(HttpStatus.SC_BAD_REQUEST); | ||
assertThat(response.status(), equalTo(HttpStatus.SC_BAD_REQUEST)); | ||
} | ||
|
||
private ResponseException buildResponseException(final int statusCode) throws IOException { | ||
return new ResponseException(this.buildTestResponse(statusCode)); | ||
} | ||
|
||
private Response buildTestResponse(final int statusCode) { | ||
return new Response( | ||
new RequestLine("GET", "/", HttpVersion.HTTP_1_1), | ||
new HttpHost("localhost"), | ||
new BasicClassicHttpResponse(statusCode) | ||
); | ||
} | ||
|
||
} |