diff --git a/command/src/com/mirth/connect/cli/CommandLineInterface.java b/command/src/com/mirth/connect/cli/CommandLineInterface.java index 1e785ab14..e1582bfaa 100644 --- a/command/src/com/mirth/connect/cli/CommandLineInterface.java +++ b/command/src/com/mirth/connect/cli/CommandLineInterface.java @@ -58,6 +58,7 @@ import com.mirth.connect.client.core.PaginatedEventList; import com.mirth.connect.client.core.PaginatedMessageList; import com.mirth.connect.client.core.PropertiesConfigurationUtil; +import com.mirth.connect.client.core.UnauthorizedException; import com.mirth.connect.donkey.model.channel.DeployedState; import com.mirth.connect.donkey.model.message.ContentType; import com.mirth.connect.donkey.model.message.Message; @@ -179,11 +180,22 @@ private void runShell(String server, String user, String password, String script client = new Client(server); this.debug = debug; - LoginStatus loginStatus = client.login(user, password); - - if (loginStatus.getStatus() != LoginStatus.Status.SUCCESS) { - error("Could not login to server.", null); - return; + LoginStatus loginStatus = null; + try { + loginStatus = client.login(user, password); + } catch (UnauthorizedException ex) { + if (ex.getResponse() instanceof LoginStatus status && status.isSuccess()) { + loginStatus = status; + } + } + finally { + if (loginStatus == null) { + error("Could not login to server"); + System.exit(70); + } + else if (!loginStatus.isSuccess()) { + error("Could not login to server. Please check your username and password and try again.", null); System.exit(77); + } } String serverVersion = client.getVersion();