From d99640345a5427445e1896436d85758b476381a4 Mon Sep 17 00:00:00 2001 From: VivianDee <115420678+VivianDee@users.noreply.github.com> Date: Mon, 27 Oct 2025 19:42:23 +0100 Subject: [PATCH] [fix]: swagger and health check response --- app/api/integrations/simbrella.py | 32 +++++++++++++++++-------------- app/api/routes/routes.py | 6 +++--- app/swagger/digifi_swagger.json | 4 ++-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/api/integrations/simbrella.py b/app/api/integrations/simbrella.py index bab1fb4..58171f4 100644 --- a/app/api/integrations/simbrella.py +++ b/app/api/integrations/simbrella.py @@ -1,3 +1,4 @@ +from os import access import httpx import time from app.utils.logger import logger @@ -29,7 +30,7 @@ class SimbrellaIntegration: headers = {"Content-Type": "application/json"} 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.raise_for_status() @@ -41,9 +42,9 @@ class SimbrellaIntegration: SimbrellaIntegration._token_expiry = time.time() + expires_in - 60 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 except Exception as e: @@ -76,12 +77,14 @@ class SimbrellaIntegration: "channel": "USSD" } - headers = { - "Content-Type": "application/json", - "Authorization": f"Bearer {SimbrellaIntegration._get_token()}" - } - 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) logger.info(f"This is Response: {str(response)}", exc_info=True) @@ -95,22 +98,23 @@ class SimbrellaIntegration: @staticmethod def health_check(): """ - Health check for Simbrella Service + Health check for Bank Service """ 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: + access_token = SimbrellaIntegration._get_token() headers = { "Content-Type": "application/json", - "Authorization": f"Bearer {SimbrellaIntegration._get_token()}" + "Authorization": f"Bearer {access_token}" } 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 except Exception as e: - logger.error(f"Simbrella Health Check API call failed: {str(e)}", exc_info=True) - raise Exception(f"Simbrella Health Check API call failed: {str(e)}") + logger.error(f"Bank Health Check API call failed: {str(e)}", exc_info=True) + raise Exception(f"Bank Health Check API call failed: {str(e)}") diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 231a426..6e63009 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -163,19 +163,19 @@ def health_check(): status = "failed" errors.append(f"Events Service connection failed: {str(e)}") - # Check Emulator health + # Check Bank health try: emulator_response = SimbrellaIntegration.health_check() if emulator_response.status_code != 200: bank_status = "Connection Failed" status = "failed" - errors.append(f"Emulator response: {emulator_response.text}") + errors.append(f"Bank Connection response: {emulator_response.text}") except Exception as e: bank_status = "Connection Failed" status = "failed" - errors.append(f"Emulator connection failed: {str(e)}") + errors.append(f"Connection to Bank failed: {str(e)}") response = { diff --git a/app/swagger/digifi_swagger.json b/app/swagger/digifi_swagger.json index ab4fa0b..423ba5b 100644 --- a/app/swagger/digifi_swagger.json +++ b/app/swagger/digifi_swagger.json @@ -104,7 +104,7 @@ "status": "ok", "db_status": "Connection Successful", "events_service_status":"Connection Successful", - "emulator_status":"Connection Successful", + "bank_status":"Connection Successful", "db_uri": "postgresql://user:****@localhost:5432/digifi_db", "error": [] } @@ -119,7 +119,7 @@ "status": "failed", "db_status": "Connection Failed", "events_service_status":"Connection Failed", - "emulator_status":"Connection Failed", + "bank_status":"Connection Failed", "db_uri": "Unavailable", "error":["could not connect to server: Connection refused"] }