Skip to content

Commit 058064c

Browse files
authored
Only provide sanitized message to exception message. (#1646)
An office with invalid characters that caused the sanitizeOrNul method to return null would cause the method to put the original exception message into the details portion. Modified invalid office and invalid unit builders to only provide the sanitized, and if null simpler, messages to the generated exception.
1 parent 255f74f commit 058064c

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

cwms-data-api/src/main/java/cwms/cda/data/dao/JooqDao.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,19 +691,20 @@ private static InvalidItemException buildInvalidOffice(RuntimeException input) {
691691

692692
Throwable cause = (input instanceof DataAccessException) ? input.getCause() : input;
693693
String localizedMessage = cause.getLocalizedMessage();
694+
String sanitizedMessage = null;
694695
if (localizedMessage != null) {
695696
Matcher matcher = INVALID_OFFICE_ID.matcher(localizedMessage);
696697
if (matcher.find()) {
697698
String office = sanitizeOrNull(matcher.group(1));
698699
if (office != null) {
699-
localizedMessage = "\"" + office + "\" is not a valid CWMS office id";
700+
sanitizedMessage = "\"" + office + "\" is not a valid CWMS office id";
700701
}
701702
}
702703
}
703-
if (localizedMessage == null || localizedMessage.isEmpty()) {
704-
localizedMessage = "Invalid Office.";
704+
if (sanitizedMessage == null || sanitizedMessage.isEmpty()) {
705+
sanitizedMessage = "Invalid Office.";
705706
}
706-
return new InvalidItemException(localizedMessage, cause);
707+
return new InvalidItemException(sanitizedMessage, cause);
707708
}
708709

709710
public static boolean isUnsupportedOperationException(RuntimeException input) {

0 commit comments

Comments
 (0)