mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-30 04:36:39 +00:00
feat: add method to KanidmQueryError
This commit is contained in:
parent
2e5a8c8b7b
commit
102f6f1e71
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue