Till Westmann has submitted this change and it was merged. Change subject: Improved Error Reporting When Repsonse Is Non-JSON ......................................................................
Improved Error Reporting When Repsonse Is Non-JSON Change-Id: I2d27945a1d39bdc3304abcb8fd75c5173aee74c4 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1099 Sonar-Qube: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Reviewed-by: Till Westmann <[email protected]> Integration-Tests: Jenkins <[email protected]> --- M asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java 1 file changed, 17 insertions(+), 8 deletions(-) Approvals: Till Westmann: Looks good to me, approved Jenkins: Verified; No violations found; Verified diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java index 3321065..47290e7 100644 --- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java +++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java @@ -58,6 +58,7 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.StandardHttpRequestRetryHandler; import org.apache.http.util.EntityUtils; +import org.json.JSONException; import org.json.JSONObject; public class TestExecutor { @@ -267,14 +268,22 @@ // In future this may be changed depending on the requested // output format sent to the servlet. String errorBody = EntityUtils.toString(httpResponse.getEntity()); - JSONObject result = new JSONObject(errorBody); - String[] errors = { result.getJSONArray("error-code").getString(0), result.getString("summary"), - result.getString("stacktrace") }; - GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, errors[2]); - String exceptionMsg = "HTTP operation failed: " + errors[0] - + "\nSTATUS LINE: " + httpResponse.getStatusLine() - + "\nSUMMARY: " + errors[1] + "\nSTACKTRACE: " + errors[2]; - throw new Exception(exceptionMsg); + try { + JSONObject result = new JSONObject(errorBody); + String[] errors = {result.getJSONArray("error-code").getString(0), result.getString("summary"), + result.getString("stacktrace")}; + GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, errors[2]); + String exceptionMsg = "HTTP operation failed: " + errors[0] + + "\nSTATUS LINE: " + httpResponse.getStatusLine() + + "\nSUMMARY: " + errors[1] + "\nSTACKTRACE: " + errors[2]; + throw new Exception(exceptionMsg); + } catch (JSONException e) { + GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, errorBody); + String exceptionMsg = "HTTP operation failed: response is not valid-JSON (see nested exception)" + + "\nSTATUS LINE: " + httpResponse.getStatusLine() + + "\nERROR_BODY: " + errorBody; + throw new Exception(exceptionMsg, e); + } } return httpResponse; } -- To view, visit https://asterix-gerrit.ics.uci.edu/1099 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2d27945a1d39bdc3304abcb8fd75c5173aee74c4 Gerrit-PatchSet: 2 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Michael Blow <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Till Westmann <[email protected]>
