So I am having multiple occurrences of similar snippets in my code:
val optionValue = try {
Some(config.getString(key))
} catch {
case _: Missing => None
}
I want to somehow eliminate this duplicates from my code. I know that typesafe provides a way to give a fallback config file to provide default config values. However, in my case, I am not having any default values for some properties. They are optional properties.
What will be the most optimal way to refactor this code.
This is not how the library works, according https://github.com/lightbend/config#how-to-handle-defaults.
You should use withFallback
method to provide a clean configuration.