@@ -513,16 +513,16 @@ def _get_api_token_data(self, apitoken) -> tuple[str | None, list | None]:
513513 apitoken [:4 ],
514514 apitoken [- 4 :],
515515 )
516- except requests .exceptions .ProxyError :
516+ except requests .exceptions .ProxyError as proxy_error :
517517 LOGGER .critical ("apisession:_get_api_token_data:proxy not valid..." )
518518 CONSOLE .critical ("Proxy not valid...\r \n " )
519- sys . exit ( 0 )
519+ raise ConnectionError ( "Proxy not valid" ) from proxy_error
520520 except requests .exceptions .ConnectionError as connexion_error :
521521 LOGGER .critical (
522522 "apirequest:mist_post:Connection Error: %s" , connexion_error
523523 )
524524 CONSOLE .critical ("Connexion error...\r \n " )
525- sys . exit ( 0 )
525+ raise ConnectionError ( f"Connection error: { connexion_error } " ) from connexion_error
526526 except Exception :
527527 LOGGER .error (
528528 "apisession:_get_api_token_data:"
@@ -546,7 +546,7 @@ def _get_api_token_data(self, apitoken) -> tuple[str | None, list | None]:
546546 CONSOLE .critical (
547547 f"Invalid API Token { apitoken [:4 ]} ...{ apitoken [- 4 :]} : status code { data .status_code } \r \n "
548548 )
549- sys . exit ( 2 )
549+ raise ValueError ( f"Invalid API Token { apitoken [: 4 ] } ... { apitoken [ - 4 :] } : status code { data . status_code } " )
550550
551551 if data_json .get ("email" ):
552552 token_type = "user" # nosec bandit B105
@@ -691,16 +691,16 @@ def _process_login(self, retry: bool = True) -> str | None:
691691 )
692692 if retry :
693693 return self ._process_login (retry )
694- except requests .exceptions .ProxyError :
694+ except requests .exceptions .ProxyError as proxy_error :
695695 LOGGER .critical ("apisession:_process_login:proxy not valid..." )
696696 CONSOLE .critical ("Proxy not valid...\r \n " )
697- sys . exit ( 0 )
697+ raise ConnectionError ( "Proxy not valid" ) from proxy_error
698698 except requests .exceptions .ConnectionError as connexion_error :
699699 LOGGER .critical (
700700 "apirequest:mist_post:Connection Error: %s" , connexion_error
701701 )
702702 CONSOLE .critical ("Connexion error...\r \n " )
703- sys . exit ( 0 )
703+ raise ConnectionError ( f"Connection error: { connexion_error } " ) from connexion_error
704704 except Exception :
705705 LOGGER .error ("apisession:_process_login:Exception occurred" , exc_info = True )
706706 error = "Exception occurred during authentication"
@@ -1078,7 +1078,7 @@ def _getself(self) -> bool:
10781078 elif resp .proxy_error :
10791079 LOGGER .critical ("apisession:_getself:proxy not valid..." )
10801080 CONSOLE .critical ("Proxy not valid...\r \n " )
1081- sys . exit ( 0 )
1081+ raise ConnectionError ( "Proxy not valid" )
10821082 else :
10831083 LOGGER .error ("apisession:_getself:authentication not valid..." )
10841084 CONSOLE .error ("Authentication not valid...\r \n " )
@@ -1089,7 +1089,7 @@ def _getself(self) -> bool:
10891089 self ._process_login ()
10901090 return self ._getself ()
10911091 else :
1092- sys . exit ( 0 )
1092+ raise ValueError ( "Authentication not valid and user declined to retry" )
10931093 return False
10941094
10951095 ####################################
0 commit comments