55from click ._compat import get_text_stderr
66from py42 .exceptions import Py42ForbiddenError
77from py42 .exceptions import Py42HTTPError
8+ from py42 .exceptions import Py42InvalidRuleOperationError
9+ from py42 .exceptions import Py42LegalHoldNotFoundOrPermissionDeniedError
10+ from py42 .exceptions import Py42UserAlreadyAddedError
811
912from code42cli .logger import get_main_cli_logger
1013from code42cli .logger import get_view_error_details_message
@@ -52,19 +55,6 @@ def format_message(self):
5255 )
5356
5457
55- class UserAlreadyAddedError (Code42CLIError ):
56- def __init__ (self , username , list_name ):
57- msg = "'{}' is already on the {}." .format (username , list_name )
58- super ().__init__ (msg )
59-
60-
61- class InvalidRuleTypeError (Code42CLIError ):
62- def __init__ (self , rule_id , source ):
63- msg = "Only alert rules with a source of 'Alerting' can be targeted by this command. "
64- msg += "Rule {0} has a source of '{1}'."
65- super ().__init__ (msg .format (rule_id , source ))
66-
67-
6858class UserDoesNotExistError (Code42CLIError ):
6959 """An error to represent a username that is not in our system. The CLI shows this error when
7060 the user tries to add or remove a user that does not exist. This error is not shown during
@@ -77,20 +67,12 @@ def __init__(self, username):
7767class UserNotInLegalHoldError (Code42CLIError ):
7868 def __init__ (self , username , matter_id ):
7969 super ().__init__ (
80- "User '{}' is not an active member of legal hold matter '{}'" .format (
70+ "User '{}' is not an active member of legal hold matter '{}'. " .format (
8171 username , matter_id
8272 )
8373 )
8474
8575
86- class LegalHoldNotFoundOrPermissionDeniedError (Code42CLIError ):
87- def __init__ (self , matter_id ):
88- super ().__init__ (
89- "Matter with id={} either does not exist or your profile does not have permission to "
90- "view it." .format (matter_id )
91- )
92-
93-
9476class ExceptionHandlingGroup (click .Group ):
9577 """Custom click.Group subclass to add custom exception handling."""
9678
@@ -124,6 +106,15 @@ def invoke(self, ctx):
124106 except click .exceptions .Exit :
125107 raise
126108
109+ except (
110+ UserDoesNotExistError ,
111+ Py42UserAlreadyAddedError ,
112+ Py42InvalidRuleOperationError ,
113+ Py42LegalHoldNotFoundOrPermissionDeniedError ,
114+ ) as err :
115+ self .logger .log_error (err )
116+ raise Code42CLIError (str (err ))
117+
127118 except Py42ForbiddenError as err :
128119 self .logger .log_verbose_error (self ._original_args , err .response .request )
129120 raise LoggedCLIError (
0 commit comments