jp (account): better exit code handling

This commit is contained in:
Goffi 2020-12-04 12:32:56 +01:00
commit 095ec0c71a

View file

@ -20,13 +20,15 @@
"""This module permits to manage XMPP accounts using in-band registration (XEP-0077)"""
from sat_frontends.jp.constants import Const as C
from sat_frontends.bridge.bridge_frontend import BridgeException
from sat.core.log import getLogger
log = getLogger(__name__)
from sat.core.i18n import _
from sat_frontends.jp import base
from sat_frontends.tools import jid
log = getLogger(__name__)
__commands__ = ["Account"]
@ -83,11 +85,22 @@ class AccountCreate(base.CommandBase):
self.args.host,
self.args.port,
)
except BridgeException as e:
if e.condition == 'conflict':
self.disp(
f"The account {self.args.jid} already exists",
error=True
)
self.host.quit(C.EXIT_CONFLICT)
else:
self.disp(
f"can't create account on {self.args.host or 'localhost'!r} with jid "
f"{self.args.jid!r} using In-Band Registration: {e}", error=True)
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
except Exception as e:
self.disp(
f"can't create account on {self.args.host or 'localhost'!r} with jid "
f"{self.args.jid!r} using In-Band Registration: {e}", error=True)
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
self.disp(f"Internal error: {e}", error=True)
self.host.quit(C.EXIT_INTERNAL_ERROR)
self.disp(_("XMPP account created"), 1)
@ -102,13 +115,23 @@ class AccountCreate(base.CommandBase):
self.args.password,
"",
)
except BridgeException as e:
if e.condition == 'conflict':
self.disp(
f"The profile {self.args.profile} already exists",
error=True
)
self.host.quit(C.EXIT_CONFLICT)
else:
self.disp(
_(f"Can't create profile {self.args.profile} to associate with jid "
f"{self.args.jid}: {e}"),
error=True,
)
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
except Exception as e:
self.disp(
_(f"Can't create profile {self.args.profile} to associate with jid "
f"{self.args.jid}: {e}"),
error=True,
)
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
self.disp(f"Internal error: {e}", error=True)
self.host.quit(C.EXIT_INTERNAL_ERROR)
self.disp(_("profile created"), 1)
try: