Improved Error Reporting When Repsonse Is Non-JSON
Change-Id: I2d27945a1d39bdc3304abcb8fd75c5173aee74c4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1099
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
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;
}