Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
added http response code to JestResult - #208 & #220
Browse files Browse the repository at this point in the history
  • Loading branch information
kramer committed Jul 8, 2015
1 parent 372017a commit 4f04175
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public AbstractAction(Builder builder) {

protected T createNewElasticSearchResult(T result, String responseBody, int statusCode, String reasonPhrase, Gson gson) {
JsonObject jsonMap = parseResponseBody(responseBody);
result.setResponseCode(statusCode);
result.setJsonString(responseBody);
result.setJsonObject(jsonMap);
result.setPathToResult(getPathToResult());
Expand Down
10 changes: 10 additions & 0 deletions jest-common/src/main/java/io/searchbox/client/JestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class JestResult {
protected JsonObject jsonObject;
protected String jsonString;
protected String pathToResult;
protected int responseCode;
protected boolean isSucceeded;
protected String errorMessage;
protected Gson gson;
Expand All @@ -37,6 +38,7 @@ public JestResult(JestResult source) {
this.jsonObject = source.jsonObject;
this.jsonString = source.jsonString;
this.pathToResult = source.pathToResult;
this.responseCode = source.responseCode;
this.isSucceeded = source.isSucceeded;
this.errorMessage = source.errorMessage;
this.gson = source.gson;
Expand Down Expand Up @@ -78,6 +80,14 @@ public String getErrorMessage() {
return errorMessage;
}

public int getResponseCode() {
return responseCode;
}

public void setResponseCode(int responseCode) {
this.responseCode = responseCode;
}

/**
* manually set an error message, eg. for the cases where non-200 response code is received
*/
Expand Down
1 change: 1 addition & 0 deletions jest-common/src/main/java/io/searchbox/core/Bulk.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public BulkResult createNewElasticSearchResult(String responseBody, int statusCo
@Override
protected BulkResult createNewElasticSearchResult(BulkResult result, String responseBody, int statusCode, String reasonPhrase, Gson gson) {
JsonObject jsonMap = parseResponseBody(responseBody);
result.setResponseCode(statusCode);
result.setJsonString(responseBody);
result.setJsonObject(jsonMap);
result.setPathToResult(getPathToResult());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public void getSuccessIndexResult() {
Index index = new Index.Builder("{\"abc\":\"dce\"}").index("test").build();
JestResult result = index.createNewElasticSearchResult(jsonString, 200, null, new Gson());
assertTrue(result.getErrorMessage(), result.isSucceeded());
assertEquals(200, result.getResponseCode());
}

@Test
Expand Down

0 comments on commit 4f04175

Please sign in to comment.