From 095ec0c71ade2aee61d39f4e4a59e7ea46b73689 Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 4 Dec 2020 12:32:56 +0100 Subject: [PATCH] jp (account): better exit code handling --- sat_frontends/jp/cmd_account.py | 47 ++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/sat_frontends/jp/cmd_account.py b/sat_frontends/jp/cmd_account.py index 2006cc8c..16971841 100644 --- a/sat_frontends/jp/cmd_account.py +++ b/sat_frontends/jp/cmd_account.py @@ -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: