How are you supposed to parse the object returned by DSResponse.getErrors()? It appears in some responses as a Map<String,Map<String,String>> and in other responses as a Map<String,List<String>>.
Is there some helper code to convert it into a consistent object? Although the documentation is not clear on this point (in the JS example it appears to be a map of String,String), I would have thought it would be a Map<String,List<String>> where the String is field name and the List<String> is the list of error messages for that field.
I need to take the errors in a DSResponse and show them in a warning popup. This code seems to handle both cases I've encountered so far but there must be an easier way.
Is there some helper code to convert it into a consistent object? Although the documentation is not clear on this point (in the JS example it appears to be a map of String,String), I would have thought it would be a Map<String,List<String>> where the String is field name and the List<String> is the list of error messages for that field.
I need to take the errors in a DSResponse and show them in a warning popup. This code seems to handle both cases I've encountered so far but there must be an easier way.
Code:
Map<String,Object> errors = response.getErrors();
StringBuilder sb = new StringBuilder();
for (Object error : errors.values()) {
if (error instanceof List) {
sb.append("Errors (list)");
for (Map<String, String> errorMap : (List<Map<String,String>>)error) {
for (String errorMessage : errorMap.values()) {
sb.append("</br>");
sb.append(errorMessage);
}
}
}
if (error instanceof Map) {
sb.append("Errors (map)");
for (String errorMessage : ((Map<String,String>)error).values()) {
sb.append("</br>");
sb.append(errorMessage);
}
}
}
SC.warn(sb.toString(), new BooleanCallback() {
@Override
public void execute(Boolean value) {
grid.startEditing(event.getRowNum(), event.getColNum(), false);
}
});
Comment