Skip to content

Implement nested error message handling for schema validation #13045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ public boolean handleRequest(MessageContext messageContext) {
if (validationReport.hasErrors()) {
StringBuilder finalMessage = new StringBuilder();
for (ValidationReport.Message message : validationReport.getMessages()) {
finalMessage.append(message.getMessage()).append(", ");
finalMessage.append(getErrorMessage(message)).append(", ");
}
// Remove the last comma and space, if present
if (finalMessage.length() > 0) {
finalMessage.setLength(finalMessage.length() - 2);
}
String errMessage = "Schema validation failed in the Request: ";
logger.error(errMessage);
Expand All @@ -101,7 +105,11 @@ public boolean handleResponse(MessageContext messageContext) {
if (validationReport.hasErrors()) {
StringBuilder finalMessage = new StringBuilder();
for (ValidationReport.Message message : validationReport.getMessages()) {
finalMessage.append(message.getMessage()).append(", ");
finalMessage.append(getErrorMessage(message)).append(", ");
}
// Remove the last comma and space, if present
if (finalMessage.length() > 0) {
finalMessage.setLength(finalMessage.length() - 2);
}
String errMessage = "Schema validation failed in the Response: ";
logger.error(errMessage);
Expand All @@ -110,4 +118,16 @@ public boolean handleResponse(MessageContext messageContext) {
}
return true;
}

private String getErrorMessage(ValidationReport.Message message){
if(message.getNestedMessages().isEmpty()){
return message.getMessage();
}
StringBuilder combinedMessages = new StringBuilder();
combinedMessages.append(message.getMessage());
for (ValidationReport.Message nestedMessage : message.getNestedMessages()) {
combinedMessages.append(", ").append(getErrorMessage(nestedMessage));
}
return combinedMessages.toString().trim();
}
}
Loading