I am using the below method to check if the response was successful or not. In the event of an error a warning message is being displayed to the user.
Everything works fine except the fact that the error msg is being displayed in the Dialog box as a JSON object: {"errorMsg" : "Invalid DB details. Connection cannot be established"}.
My response looks like the one below.
{
"response" : {
"status" : "error",
"startRow" : 0,
"endRow" : 0,
"totalRows" : 0,
"errors" : {
"errorMsg" : "Invalid input details. Connection cannot be established"
}
}
}
Everything works fine except the fact that the error msg is being displayed in the Dialog box as a JSON object: {"errorMsg" : "Invalid DB details. Connection cannot be established"}.
My response looks like the one below.
{
"response" : {
"status" : "error",
"startRow" : 0,
"endRow" : 0,
"totalRows" : 0,
"errors" : {
"errorMsg" : "Invalid input details. Connection cannot be established"
}
}
}
Code:
@Override
protected void transformResponse(DSResponse response, DSRequest request, Object jsonData) {
JSONArray value = XMLTools.selectObjects(jsonData, "/response/status");
String status = ((JSONString) value.get(0)).stringValue();
if (!status.equals("success")) {
response.setStatus(RPCResponse.STATUS_VALIDATION_ERROR);
JSONArray errors = XMLTools.selectObjects(jsonData, "/response/errors");
response.setErrors(errors.getJavaScriptObject());
StringBuilder builder = new StringBuilder();
for (int i = 0; i < errors.size(); i++) {
builder.append(errors.get(i));
}
Dialog base = new Dialog();
base.setShowModalMask(true);
SC.warn("Error",builder.toString(), new BooleanCallback() {
@Override
public void execute(Boolean aBoolean) { }
}, new UIBaseModalDialog());
}
}