Skip to content

Commit

Permalink
refactor sep1helper
Browse files Browse the repository at this point in the history
  • Loading branch information
reecexlm committed Aug 11, 2023
1 parent 7288802 commit 7a4cec4
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions core/src/main/java/org/stellar/anchor/util/Sep1Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 7a4cec4

Please sign in to comment.