diff --git a/app/__init__.py b/app/__init__.py index f1c1d5fe4..a6eeb27c7 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -118,6 +118,8 @@ from notifications_utils.formatters import ( from notifications_utils.recipients import format_phone_number_human_readable from notifications_utils.url_safe_token import generate_token +from app.utils.api_health import is_api_down + login_manager = LoginManager() csrf = CSRFProtect() talisman = Talisman() @@ -185,6 +187,10 @@ def create_app(application): # FEATURE_ABOUT_PAGE_ENABLED=feature_about_page_enabled, # ) + @application.context_processor + def inject_is_api_down(): + return {"is_api_down": is_api_down()} + @application.context_processor def inject_initial_signin_url(): ttl = 24 * 60 * 60 diff --git a/app/main/views/index.py b/app/main/views/index.py index 79cac7252..65ee5a2c7 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -19,7 +19,6 @@ from app.main.views.sub_navigation_dictionaries import ( about_notify_nav, using_notify_nav, ) -from app.utils.api_health import is_api_down from app.utils.user import user_is_logged_in logger = logging.getLogger(__name__) @@ -47,16 +46,10 @@ def index(): if current_user and current_user.is_authenticated: return redirect(url_for("main.choose_account")) - try: - counts = status_api_client.get_count_of_live_services_and_organizations() - except Exception as e: - logger.warning(f"API down when loading homepage: {e}") - counts = None return render_template( "views/signedout.html", sms_rate=CURRENT_SMS_RATE, - counts=counts, - is_api_down=is_api_down(), + counts=status_api_client.get_count_of_live_services_and_organizations() ) diff --git a/app/templates/base.html b/app/templates/base.html index f482d8f37..80a0afc7f 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -29,29 +29,31 @@ {% block header %} {% include 'components/usa_banner.html' %} - {% if current_user.is_authenticated or current_service or current_user.platform_admin %} -
-
-
-

Notify.gov Service Ending

-

- GSA will no longer offer the Notify.gov service after June 8th, 2025. Visit - Notify.gov Service Ending for more information. -

+ {% if not is_api_down %} + {% if current_user.is_authenticated or current_service or current_user.platform_admin %} +
+
+
+

Notify.gov Service Ending

+

+ GSA will no longer offer the Notify.gov service after June 8th, 2025. Visit + Notify.gov Service Ending for more information. +

+
-
-
- {% else %} -
-
-
-

Notify.gov Service Ending

-

- Notify.gov is no longer accepting new partners. -

+
+ {% else %} +
+
+
+

Notify.gov Service Ending

+

+ Notify.gov is no longer accepting new partners. +

+
- -
+ + {% endif %} {% endif %} {% include 'components/header.html' %} {% endblock %} diff --git a/app/utils/api_health.py b/app/utils/api_health.py index c75fef5da..b22ffd63d 100644 --- a/app/utils/api_health.py +++ b/app/utils/api_health.py @@ -1,13 +1,19 @@ import os - import requests +import logging from requests.exceptions import RequestException +logger = logging.getLogger(__name__) + def is_api_down(): - api_base_url = os.getenv("API_BASE_URL", "http://localhost:6011") + api_base_url = os.getenv("API_HOST_NAME") try: response = requests.get(api_base_url, timeout=2) - return response.status_code != 200 - except RequestException: + is_down = response.status_code != 200 + if is_down: + logger.warning(f"API responded with status {response.status_code} at {api_base_url}") + return is_down + except RequestException as e: + logger.error(f"API down when loading homepage {e}") return True