Skip to content

Commit 41e617c

Browse files
committed
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. (cherry picked from commit 058064c)
1 parent 7429acb commit 41e617c

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
@@ -671,19 +671,20 @@ private static InvalidItemException buildInvalidOffice(RuntimeException input) {
671671

672672
Throwable cause = (input instanceof DataAccessException) ? input.getCause() : input;
673673
String localizedMessage = cause.getLocalizedMessage();
674+
String sanitizedMessage = null;
674675
if (localizedMessage != null) {
675676
Matcher matcher = INVALID_OFFICE_ID.matcher(localizedMessage);
676677
if (matcher.find()) {
677678
String office = sanitizeOrNull(matcher.group(1));
678679
if (office != null) {
679-
localizedMessage = "\"" + office + "\" is not a valid CWMS office id";
680+
sanitizedMessage = "\"" + office + "\" is not a valid CWMS office id";
680681
}
681682
}
682683
}
683-
if (localizedMessage == null || localizedMessage.isEmpty()) {
684-
localizedMessage = "Invalid Office.";
684+
if (sanitizedMessage == null || sanitizedMessage.isEmpty()) {
685+
sanitizedMessage = "Invalid Office.";
685686
}
686-
return new InvalidItemException(localizedMessage, cause);
687+
return new InvalidItemException(sanitizedMessage, cause);
687688
}
688689

689690
public static boolean isUnsupportedOperationException(RuntimeException input) {

0 commit comments

Comments
 (0)