jp (account): better exit code handling
This commit is contained in:
parent
02472de2c4
commit
095ec0c71a
1 changed files with 35 additions and 12 deletions
|
|
@ -20,13 +20,15 @@
|
||||||
"""This module permits to manage XMPP accounts using in-band registration (XEP-0077)"""
|
"""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.jp.constants import Const as C
|
||||||
|
from sat_frontends.bridge.bridge_frontend import BridgeException
|
||||||
from sat.core.log import getLogger
|
from sat.core.log import getLogger
|
||||||
|
|
||||||
log = getLogger(__name__)
|
|
||||||
from sat.core.i18n import _
|
from sat.core.i18n import _
|
||||||
from sat_frontends.jp import base
|
from sat_frontends.jp import base
|
||||||
from sat_frontends.tools import jid
|
from sat_frontends.tools import jid
|
||||||
|
|
||||||
|
|
||||||
|
log = getLogger(__name__)
|
||||||
|
|
||||||
__commands__ = ["Account"]
|
__commands__ = ["Account"]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,11 +85,22 @@ class AccountCreate(base.CommandBase):
|
||||||
self.args.host,
|
self.args.host,
|
||||||
self.args.port,
|
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:
|
except Exception as e:
|
||||||
self.disp(
|
self.disp(f"Internal error: {e}", error=True)
|
||||||
f"can't create account on {self.args.host or 'localhost'!r} with jid "
|
self.host.quit(C.EXIT_INTERNAL_ERROR)
|
||||||
f"{self.args.jid!r} using In-Band Registration: {e}", error=True)
|
|
||||||
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
|
|
||||||
|
|
||||||
self.disp(_("XMPP account created"), 1)
|
self.disp(_("XMPP account created"), 1)
|
||||||
|
|
||||||
|
|
@ -102,13 +115,23 @@ class AccountCreate(base.CommandBase):
|
||||||
self.args.password,
|
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:
|
except Exception as e:
|
||||||
self.disp(
|
self.disp(f"Internal error: {e}", error=True)
|
||||||
_(f"Can't create profile {self.args.profile} to associate with jid "
|
self.host.quit(C.EXIT_INTERNAL_ERROR)
|
||||||
f"{self.args.jid}: {e}"),
|
|
||||||
error=True,
|
|
||||||
)
|
|
||||||
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
|
|
||||||
|
|
||||||
self.disp(_("profile created"), 1)
|
self.disp(_("profile created"), 1)
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue