diff --git a/core/src/main/java/org/stellar/anchor/util/Sep1Helper.java b/core/src/main/java/org/stellar/anchor/util/Sep1Helper.java index 205e820a6c..307f501e70 100644 --- a/core/src/main/java/org/stellar/anchor/util/Sep1Helper.java +++ b/core/src/main/java/org/stellar/anchor/util/Sep1Helper.java @@ -4,12 +4,19 @@ import com.moandjiezana.toml.Toml; import java.io.IOException; -import java.net.URL; import org.stellar.anchor.api.exception.InvalidConfigException; public class Sep1Helper { public static TomlContent readToml(String url) throws IOException { - return new TomlContent(new URL(url)); + try { + String tomlValue = NetUtil.fetch(url); + return new TomlContent(tomlValue); + } catch (IOException e) { + String obfuscatedMessage = + String.format("An error occurred while fetching the TOML from %s", url); + Log.error("Sep1Service fetchTomlFromURL Error fetching Toml from URL:{}", url); + throw new IOException(obfuscatedMessage); // Preserve the original exception as the cause + } } public static TomlContent parse(String tomlString) throws InvalidConfigException { @@ -18,7 +25,7 @@ public static TomlContent parse(String tomlString) throws InvalidConfigException } catch (Exception e) { // Obfuscate the message and rethrow String obfuscatedMessage = "Failed to parse TOML content. Invalid Config."; - debugF(e.toString()); // Log the parsing exception + debugF(obfuscatedMessage); // Log the parsing exception throw new InvalidConfigException( obfuscatedMessage); // Preserve the original exception as the cause } @@ -27,19 +34,6 @@ public static TomlContent parse(String tomlString) throws InvalidConfigException public static class TomlContent { private final Toml toml; - TomlContent(URL url) throws IOException { - try { - String tomlValue = NetUtil.fetch(url.toString()); - toml = new Toml().read(tomlValue); - } catch (IOException e) { - // Obfuscate the message and rethrow - String obfuscatedMessage = - String.format("An error occurred while fetching the TOML from %s", url); - Log.error("Sep1Service fetchTomlFromURL Error fetching Toml from URL:{}", url); - throw new IOException(obfuscatedMessage); // Preserve the original exception as the cause - } - } - TomlContent(String tomlString) { toml = new Toml().read(tomlString); }