forked from DigiFi/digifi-BankToProductCore
[fix]: swagger and health check response
This commit is contained in:
@@ -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)}")
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user