Skip to content

Commit

Permalink
[core] Make BindException more user friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
tipsy committed May 6, 2018
1 parent 1759766 commit 2786579
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/io/javalin/Javalin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.javalin.event.EventType;
import io.javalin.security.AccessManager;
import io.javalin.security.Role;
import java.net.BindException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -133,6 +134,13 @@ public Javalin start() {
eventManager.fireEvent(EventType.SERVER_STARTED, this);
} catch (Exception e) {
log.error("Failed to start Javalin", e);
if (e instanceof BindException && e.getMessage() != null) {
if (e.getMessage().toLowerCase().contains("in use")) {
log.error("Port already in use. Make sure no other process is using port " + port + " and try again.");
} else if (e.getMessage().toLowerCase().contains("permission denied")) {
log.error("Port 1-1023 require elevated privileges (process must be started by admin).");
}
}
eventManager.fireEvent(EventType.SERVER_START_FAILED, this);
}
}
Expand Down

0 comments on commit 2786579

Please sign in to comment.