fix: add endpoint debug

This commit is contained in:
dettlaff 2024-11-11 20:36:16 +04:00
parent c056540578
commit 239c47964c
2 changed files with 4 additions and 5 deletions

View file

@ -20,10 +20,11 @@ class KanidmUserRepository(AbstractUserRepository):
@staticmethod @staticmethod
def _send_query(endpoint: str, method: str = "GET", data=None): def _send_query(endpoint: str, method: str = "GET", data=None):
request_method = getattr(requests, method.lower(), None) request_method = getattr(requests, method.lower(), None)
full_endpoint = f"{KANIDM_URL}/v1/{endpoint}"
try: try:
response = request_method( response = request_method(
f"{KANIDM_URL}/v1/{endpoint}", full_endpoint,
json=data, json=data,
headers={ headers={
"Authorization": f"Bearer {TEST_TOKEN}", "Authorization": f"Bearer {TEST_TOKEN}",
@ -33,9 +34,8 @@ class KanidmUserRepository(AbstractUserRepository):
) )
if response.status_code != 200: if response.status_code != 200:
error_text = getattr(response, "text", "No response error was found...")
raise KanidmQueryError( raise KanidmQueryError(
f"Kanidm returned {response.status_code} unexpected HTTP status code. Error: {error_text}." f"Kanidm returned {response.status_code} unexpected HTTP status code. Endpoint: {full_endpoint}. Error: {response.text}."
) )
json = response.json() json = response.json()
return json["data"] return json["data"]

View file

@ -70,9 +70,8 @@ class MonitoringQueries:
timeout=0.8, timeout=0.8,
) )
if response.status_code != 200: if response.status_code != 200:
error_text = getattr(response, "text", "No response error was found...")
return MonitoringQueryError( return MonitoringQueryError(
error=f"Prometheus returned unexpected HTTP status code. Error: {error_text}. The query was {query}" error=f"Prometheus returned unexpected HTTP status code. Error: {response.text}. The query was {query}"
) )
json = response.json() json = response.json()
if result_type and json["data"]["resultType"] != result_type: if result_type and json["data"]["resultType"] != result_type: