feat(log): log the failure na d sucess of interface

This commit is contained in:
YuehuCao 2025-09-17 17:57:37 +08:00
parent 9473c19141
commit f27080452c

View File

@ -31,15 +31,22 @@ class ApiKeyIntrospectHandler:
HTTPException: If the external service call fails HTTPException: If the external service call fails
""" """
api_url = self.auth_service_base + "introspect_api_key" api_url = self.auth_service_base + "introspect_api_key"
await self.module_logger.log_info(f"Starting API Key validation for key: {api_key[:8]}...")
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
response = await client.post( response = await client.post(
api_url, api_url,
json={"api_key": api_key} json={"api_key": api_key}
) )
if response.status_code != 200: if response.status_code != 200:
error_detail = response.json() if response.content else {"error": "Unknown error"} error_detail = response.json() if response.content else {"error": "Unknown error"}
await self.module_logger.log_error(f"API Key validation failed - Status: {response.status_code}, Error: {error_detail}")
raise HTTPException( raise HTTPException(
status_code=response.status_code, status_code=response.status_code,
detail=error_detail detail=error_detail
) )
return response.json()
validation_result = response.json()
await self.module_logger.log_info(f"API Key validation successful - Active: {validation_result.get('active', False)}")
return validation_result