*/
public static String parseJsonExceptionString(String jsonErrorResponse)
{
- String errorMessage = "RunTime error";
+ StringBuilder errorMessage = new StringBuilder(
+ "\n============= PDB Rest Client RunTime error =============\n");
try
{
JSONParser jsonParser = new JSONParser();
JSONObject jsonObj = (JSONObject) jsonParser.parse(jsonErrorResponse);
JSONObject errorResponse = (JSONObject) jsonObj.get("error");
- errorMessage = errorResponse.get("msg").toString();
-
JSONObject responseHeader = (JSONObject) jsonObj
.get("responseHeader");
- errorMessage += responseHeader.get("params").toString();
+ JSONObject paramsObj = (JSONObject) responseHeader.get("params");
+ String status = responseHeader.get("status").toString();
+ String message = errorResponse.get("msg").toString();
+ String query = paramsObj.get("q").toString();
+ String fl = paramsObj.get("fl").toString();
+
+ errorMessage.append("Status: ").append(status).append("\n");
+ errorMessage.append("Message: ").append(message).append("\n");
+ errorMessage.append("query: ").append(query).append("\n");
+ errorMessage.append("fl: ").append(fl).append("\n");
} catch (ParseException e)
{
e.printStackTrace();
}
- return errorMessage;
+ return errorMessage.toString();
}
/**
wantedFields.add(PDBDocField.GENUS);
wantedFields.add(PDBDocField.GENE_NAME);
wantedFields.add(PDBDocField.TITLE);
- assertEquals("molecule_type,pdb_id,genus,gene_name,title",
- PDBRestClient
- .getPDBDocFieldsAsCommaDelimitedString(wantedFields));
+
+ String expectedResult = "molecule_type,pdb_id,genus,gene_name,title";
+ String actualResult = PDBRestClient
+ .getPDBDocFieldsAsCommaDelimitedString(wantedFields);
+
+ assertEquals("", expectedResult, actualResult);
}
@Test
String parsedErrorResponse = PDBRestClient
.parseJsonExceptionString(jsonErrorResponse);
- String expectedErrorMsg = "org.apache.solr.search.SyntaxError: Cannot parse 'text:abc OR text:go:abc AND molecule_sequence:['' TO *]': Encountered \" \":\" \": \"\" at line 1, column 19.{\"q\":\"text:abc OR text:go:abc AND molecule_sequence:['' TO *]\",\"fl\":\"pdb_id\",\"sort\":\"\",\"rows\":\"100\",\"wt\":\"json\"}";
+ System.out.println(parsedErrorResponse);
+ String expectedErrorMsg = "\n============= PDB Rest Client RunTime error =============\n"
+ + "Status: 400\n"
+ + "Message: org.apache.solr.search.SyntaxError: Cannot parse 'text:abc OR text:go:abc AND molecule_sequence:['' TO *]': Encountered \" \":\" \": \"\" at line 1, column 19.\n"
+ + "query: text:abc OR text:go:abc AND molecule_sequence:['' TO *]\n"
+ + "fl: pdb_id\n";
assertEquals(expectedErrorMsg, parsedErrorResponse);
}