From a11629f543a8b43451cecc46600a78cbb6af015a Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 17 Jun 2023 18:27:30 +0200 Subject: [PATCH] Readable error messages when OMM is unreachable when using cli --- mitel_ommclient2/cli.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mitel_ommclient2/cli.py b/mitel_ommclient2/cli.py index 416ecb3..c3f9a0c 100755 --- a/mitel_ommclient2/cli.py +++ b/mitel_ommclient2/cli.py @@ -6,7 +6,7 @@ import time import traceback from . import OMMClient2 -from .exceptions import ENoEnt +from .exceptions import EAuth, ENoEnt from .messages import GetAccount, Ping # exit handling with argparse is a bit broken even with exit_on_error=False, so we hack this @@ -40,7 +40,14 @@ def main(): if not password: password = getpass.getpass(prompt="OMM password for {}@{}:".format(username, hostname)) - c = OMMClient2(hostname, username, password, ommsync=ommsync) + try: + c = OMMClient2(hostname, username, password, ommsync=ommsync) + except EAuth: + print("Authentication failed") + exit(1) + except TimeoutError: + print("OMM unreachable") + exit(1) parser = argparse.ArgumentParser(prog="ommclient2", add_help=False, exit_on_error=False) subparsers = parser.add_subparsers()