Michael Blow has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/1099
Change subject: Improved Error Reporting When Repsonse Is Non-JSON
......................................................................
Improved Error Reporting When Repsonse Is Non-JSON
Change-Id: I2d27945a1d39bdc3304abcb8fd75c5173aee74c4
---
M
asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
1 file changed, 17 insertions(+), 8 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/99/1099/1
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: newchange
Gerrit-Change-Id: I2d27945a1d39bdc3304abcb8fd75c5173aee74c4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <[email protected]>