diff --git a/selfprivacy_api/repositories/users/exceptions_kanidm.py b/selfprivacy_api/repositories/users/exceptions_kanidm.py index 29d0642..aa1e5ca 100644 --- a/selfprivacy_api/repositories/users/exceptions_kanidm.py +++ b/selfprivacy_api/repositories/users/exceptions_kanidm.py @@ -6,13 +6,19 @@ class KanidmQueryError(Exception): """Error occurred during kanidm query""" def __init__( - self, error_text: Optional[Any] = None, endpoint: Optional[str] = None + self, + error_text: Optional[Any] = None, + endpoint: Optional[str] = None, + method: Optional[str] = None, ) -> None: self.error_text = str(error_text) self.endpoint = endpoint + self.method = method def get_error_message(self) -> str: message = "An error occurred during the Kanidm query." + if self.method: + message += f" Method: {self.method}" if self.endpoint: message += f" Endpoint: {self.endpoint}" if self.error_text: diff --git a/selfprivacy_api/repositories/users/kanidm_user_repository.py b/selfprivacy_api/repositories/users/kanidm_user_repository.py index 14fa974..e7674cb 100644 --- a/selfprivacy_api/repositories/users/kanidm_user_repository.py +++ b/selfprivacy_api/repositories/users/kanidm_user_repository.py @@ -150,6 +150,7 @@ class KanidmAdminToken: raise KanidmQueryError( error_text=f"Kanidm is not responding to requests. Error: {str(error)}", endpoint=endpoint, + method="GET", ) except Exception as error: @@ -267,6 +268,7 @@ class KanidmUserRepository(AbstractUserRepository): raise KanidmQueryError( error_text=f"No JSON found in Kanidm response. Error: {str(error)}", endpoint=full_endpoint, + method=method, ) except ( requests.exceptions.Timeout, @@ -276,11 +278,14 @@ class KanidmUserRepository(AbstractUserRepository): raise KanidmQueryError( error_text=f"Kanidm is not responding to requests. Error: {str(error)}", endpoint=endpoint, + method=method, ) except Exception as error: logger.error(f"Kanidm query error: {str(error)}") - raise KanidmQueryError(error_text=error, endpoint=full_endpoint) + raise KanidmQueryError( + error_text=error, endpoint=full_endpoint, method=method + ) if response.status_code != 200: if isinstance(response_data, dict): @@ -293,13 +298,13 @@ class KanidmUserRepository(AbstractUserRepository): raise UserNotFound # does it work only for user? elif response_data == "accessdenied": raise KanidmQueryError( - error_text="Kanidm access issue", endpoint=full_endpoint + error_text="Kanidm access issue", endpoint=full_endpoint, method=method ) elif response_data == "notauthenticated": raise FailedToGetValidKanidmToken logger.error(f"Kanidm query error: {response.text}") - raise KanidmQueryError(error_text=response.text, endpoint=full_endpoint) + raise KanidmQueryError(error_text=response.text, endpoint=full_endpoint, method=method) return response_data