private List<ExceptionResponse> parseMessageToListExceptionResponse(String errorMessage) {
List<ExceptionResponse> errorList = new ArrayList<>();
// Biểu thức chính quy để tìm field và message
Pattern pattern = Pattern.compile("(\\w+\\.\\w+\\.\\w+):\\s(.*?)(?=(?:\\w+\\.\\w+\\.\\w+:\\s|$))");
Matcher matcher = pattern.matcher(errorMessage);
while (matcher.find()) {
String field = matcher.group(1).substring(matcher.group(1).lastIndexOf('.') + 1);
String message = matcher.group(2).trim(); // Loại bỏ khoảng trắng và dấu phẩy thừa
if (message.endsWith(",")) {
message = message.substring(0, message.length() - 1).trim(); // Loại bỏ dấu phẩy thừa nếu có
}
errorList.add(new ExceptionResponse(field, message));
}
return errorList;
}
Expected behavior/code
[
{
"field": "newPassword",
"message": "New password must be at least 8 characters long, contain at least one special character, one uppercase letter, and one lowercase letter"
}
]
Environment
Java version: 22.0.2
OS: Windows 10
Possible Solution
Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.
:bug: Bug Report
Current Behavior Handler exception method bug if message contains many parts that separates by commas , it only get the first part
Steps to reproduce
Input Code
GlobalExceptionHandler.java
Change to :
Expected behavior/code
Environment
Possible Solution
Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.