[fix]: swagger and health check response

This commit was merged in pull request #67.
This commit is contained in:
VivianDee
2025-10-27 19:42:23 +01:00
parent 6221447353
commit d99640345a
3 changed files with 23 additions and 19 deletions
+18 -14
View File
@@ -1,3 +1,4 @@
from os import access
import httpx import httpx
import time import time
from app.utils.logger import logger from app.utils.logger import logger
@@ -29,7 +30,7 @@ class SimbrellaIntegration:
headers = {"Content-Type": "application/json"} headers = {"Content-Type": "application/json"}
try: try:
logger.info(f"Requesting token from {url}") logger.info(f"Requesting Bank token from {url}")
response = httpx.post(url, json=payload, headers=headers, timeout=10.0) response = httpx.post(url, json=payload, headers=headers, timeout=10.0)
response.raise_for_status() response.raise_for_status()
@@ -41,9 +42,9 @@ class SimbrellaIntegration:
SimbrellaIntegration._token_expiry = time.time() + expires_in - 60 SimbrellaIntegration._token_expiry = time.time() + expires_in - 60
if not SimbrellaIntegration._access_token: if not SimbrellaIntegration._access_token:
raise Exception("Access token not found in response") raise Exception("Access token not found in Bank Authorization response")
logger.info("Successfully retrieved access token") logger.info("Successfully retrieved Bank access token")
return SimbrellaIntegration._access_token return SimbrellaIntegration._access_token
except Exception as e: except Exception as e:
@@ -76,12 +77,14 @@ class SimbrellaIntegration:
"channel": "USSD" "channel": "USSD"
} }
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {SimbrellaIntegration._get_token()}"
}
try: try:
access_token = SimbrellaIntegration._get_token()
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}"
}
response = httpx.post(url, json=payload, headers=headers, timeout=10.0) response = httpx.post(url, json=payload, headers=headers, timeout=10.0)
logger.info(f"This is Response: {str(response)}", exc_info=True) logger.info(f"This is Response: {str(response)}", exc_info=True)
@@ -95,22 +98,23 @@ class SimbrellaIntegration:
@staticmethod @staticmethod
def health_check(): def health_check():
""" """
Health check for Simbrella Service Health check for Bank Service
""" """
url = f"{SimbrellaIntegration.BASE_URL}/{SimbrellaIntegration.HEALTH_ENDPOINT}" url = f"{SimbrellaIntegration.BASE_URL}/{SimbrellaIntegration.HEALTH_ENDPOINT}"
logger.info(f"Simbrella Health Check URL: {url}") logger.info(f"Bank Health Check URL: {url}")
try: try:
access_token = SimbrellaIntegration._get_token()
headers = { headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": f"Bearer {SimbrellaIntegration._get_token()}" "Authorization": f"Bearer {access_token}"
} }
response = httpx.get(url, headers=headers, timeout=10.0) response = httpx.get(url, headers=headers, timeout=10.0)
logger.info(f"Simbrella Health Check Response: {response.text}") logger.info(f"Bank Health Check Response: {response.text}")
return response return response
except Exception as e: except Exception as e:
logger.error(f"Simbrella Health Check API call failed: {str(e)}", exc_info=True) logger.error(f"Bank Health Check API call failed: {str(e)}", exc_info=True)
raise Exception(f"Simbrella Health Check API call failed: {str(e)}") raise Exception(f"Bank Health Check API call failed: {str(e)}")
+3 -3
View File
@@ -163,19 +163,19 @@ def health_check():
status = "failed" status = "failed"
errors.append(f"Events Service connection failed: {str(e)}") errors.append(f"Events Service connection failed: {str(e)}")
# Check Emulator health # Check Bank health
try: try:
emulator_response = SimbrellaIntegration.health_check() emulator_response = SimbrellaIntegration.health_check()
if emulator_response.status_code != 200: if emulator_response.status_code != 200:
bank_status = "Connection Failed" bank_status = "Connection Failed"
status = "failed" status = "failed"
errors.append(f"Emulator response: {emulator_response.text}") errors.append(f"Bank Connection response: {emulator_response.text}")
except Exception as e: except Exception as e:
bank_status = "Connection Failed" bank_status = "Connection Failed"
status = "failed" status = "failed"
errors.append(f"Emulator connection failed: {str(e)}") errors.append(f"Connection to Bank failed: {str(e)}")
response = { response = {
+2 -2
View File
@@ -104,7 +104,7 @@
"status": "ok", "status": "ok",
"db_status": "Connection Successful", "db_status": "Connection Successful",
"events_service_status":"Connection Successful", "events_service_status":"Connection Successful",
"emulator_status":"Connection Successful", "bank_status":"Connection Successful",
"db_uri": "postgresql://user:****@localhost:5432/digifi_db", "db_uri": "postgresql://user:****@localhost:5432/digifi_db",
"error": [] "error": []
} }
@@ -119,7 +119,7 @@
"status": "failed", "status": "failed",
"db_status": "Connection Failed", "db_status": "Connection Failed",
"events_service_status":"Connection Failed", "events_service_status":"Connection Failed",
"emulator_status":"Connection Failed", "bank_status":"Connection Failed",
"db_uri": "Unavailable", "db_uri": "Unavailable",
"error":["could not connect to server: Connection refused"] "error":["could not connect to server: Connection refused"]
} }