Skip to content
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

Fix message level not found #897

Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -36,6 +36,8 @@ public class MessageSourceNotificationFactory {
private static final Logger log = logger(MessageSourceNotificationFactory.class);
public static final Object[] EMPTY_PARAMETERS = new Object[]{};
private static final String DEFAULT_CONFIRM_TEXT = "Okay";
private static final NotificationLevel DEFAULT_LEVEL = NotificationLevel.INFO;
private static final MessageType DEFAULT_MESSAGE_TYPE = MessageType.HTML;
private final MessageSource messageSource;

public MessageSourceNotificationFactory(MessageSource messageSource) {
Expand Down Expand Up @@ -153,7 +155,10 @@ private NotificationLevel parseLevel(String key, Locale locale) {
levelProperty = messageSource.getMessage("%s.level".formatted(key),
EMPTY_PARAMETERS, locale);
} catch (NoSuchMessageException e) {
throw new RuntimeException("Missing level info for %s.".formatted(key));
log.warn(
"Missing message level for `%s.level` falling back to the default of `%s`".formatted(key,
DEFAULT_LEVEL));
return DEFAULT_LEVEL;
}

try {
Expand All @@ -169,7 +174,7 @@ private String parseMessage(String key, Object[] parameters, Locale locale) {
return messageSource.getMessage("%s.message.text".formatted(key),
parameters, locale).strip();
} catch (NoSuchMessageException e) {
throw new RuntimeException("No message specified for " + key, e);
throw new RuntimeException("No message specified for `%s.message.text`".formatted(key), e);
}
}

Expand All @@ -179,8 +184,13 @@ private MessageType parseMessageType(String key, Locale locale) {
EMPTY_PARAMETERS, locale).strip().toUpperCase();
return MessageType.valueOf(messageType);
} catch (NoSuchMessageException e) {
throw new RuntimeException("No message type specified for %s.message.type".formatted(key), e);
log.warn("No message type specified for `%s.message.type`. Falling back to %s".formatted(key,
DEFAULT_MESSAGE_TYPE));
log.debug("No message type specified for `%s.message.type`. Falling back to %s".formatted(key,
DEFAULT_MESSAGE_TYPE), e);
return DEFAULT_MESSAGE_TYPE;
}

}

private Optional<String> parseTitle(String key, Locale locale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ from.experiment.to.sample.batch.level=info
from.experiment.to.sample.batch.routing.link.text=Go to Samples
experiment.created.success.message.type=html
experiment.created.success.message.text=Created experiment <strong>{0}</strong>.
experiment.created.success.message.level=success
experiment.created.success.level=success
personal-access-token.created.success.message.type=html
personal-access-token.created.success.message.text=Personal Access Token <strong>{0}</strong> was created.
personal-access-token.created.success.duration=PT8s
Expand Down