Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lennartkoopmann committed Oct 3, 2020
1 parent 29aef32 commit d59dab8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
15 changes: 13 additions & 2 deletions src/main/java/horse/wtf/nzyme/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ public static void main(String[] argv) {
}

NzymeLeader nzyme = new NzymeLeaderImpl(baseConfiguration, leaderConfiguration, database);
nzyme.initialize();

try {
nzyme.initialize();
} catch(Exception e) {
LOG.fatal("Could not initialize nzyme.", e);
System.exit(FAILURE);
}

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Thread.currentThread().setName("shutdown-hook");
Expand All @@ -127,7 +133,12 @@ public static void main(String[] argv) {
}

NzymeTracker tracker = new NzymeTrackerImpl(baseConfiguration, trackerConfiguration);
tracker.initialize();
try {
tracker.initialize();
} catch (Exception e) {
LOG.fatal("Could not initialize nzyme.", e);
System.exit(FAILURE);
}
}

while(true) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/horse/wtf/nzyme/NzymeLeaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ public void initialize() {
// Register web interface asset resources.
resourceConfig.register(WebInterfaceAssetsResource.class);

if(configuration.useTls()) {
try {
try {
if (configuration.useTls()) {
httpServer = GrizzlyHttpServerFactory.createHttpServer(
configuration.restListenUri(),
resourceConfig,
Expand All @@ -274,11 +274,11 @@ public void initialize() {
configuration.tlsKeyPath()
)
);
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException("Could not initialize secure web server.", e);
} else {
httpServer = GrizzlyHttpServerFactory.createHttpServer(configuration.restListenUri(), resourceConfig);
}
} else {
httpServer = GrizzlyHttpServerFactory.createHttpServer(configuration.restListenUri(), resourceConfig);
} catch(Exception e) {
throw new RuntimeException("Could not start web server.", e);
}

LOG.info("Started web interface and REST API at [{}]. Access it at: [{}]",
Expand Down

0 comments on commit d59dab8

Please sign in to comment.