From b4e239c9bb9c926394d783d6fc988960f4c28b35 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 17 Apr 2025 15:01:22 -0700 Subject: [PATCH 1/2] creating error page for tech difficulties --- app/main/views/index.py | 3 ++- .../error/technical_difficulties.html | 19 +++++++++++++++ app/templates/views/signedout.html | 24 ++++--------------- app/utils/api_health.py | 13 ++++++++++ notifications_utils/markdown.py | 10 ++++---- 5 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 app/templates/error/technical_difficulties.html create mode 100644 app/utils/api_health.py diff --git a/app/main/views/index.py b/app/main/views/index.py index 92e5de949..69e6a8b2e 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -19,6 +19,7 @@ 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__) @@ -51,11 +52,11 @@ def index(): except Exception as e: logger.warning(f"API down when loading homepage: {e}") counts = None - print(counts) return render_template( "views/signedout.html", sms_rate=CURRENT_SMS_RATE, counts=counts, + is_api_down=is_api_down() ) diff --git a/app/templates/error/technical_difficulties.html b/app/templates/error/technical_difficulties.html new file mode 100644 index 000000000..af6a4401d --- /dev/null +++ b/app/templates/error/technical_difficulties.html @@ -0,0 +1,19 @@ +{% block content %} +
+
+
+ Mobile phone showing error screen +
+
+

+ There's currently a technical issue. +

+

Thank you for your patience while we work on it. Notify will be back soon.

+
+
+ +
+{% endblock %} diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index 3cb35866c..624874c10 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -6,13 +6,13 @@ import usaButton %} {% block meta %} /> {% endblock %} {% block pageTitle %} Notify.gov - {% if counts %} - There's currently a technical issue {% endif %} + {% if is_api_down %} - There's currently a technical issue {% endif %} {% endblock %} {% block main %} {% block beforeContent %}{% endblock %}
- {% if counts %} + {% if is_api_down %}
@@ -24,24 +24,8 @@ import usaButton %} {% block meta %}
{% endif %} {% block content %} - {% if counts %} -
-
-
- Mobile phone showing error screen -
-
-

- There's currently a technical issue. -

-

Thank you for your patience while we work on it. Notify will be back soon.

-
-
-
- + {% if is_api_down %} + {% include "error/technical_difficulties.html" %} {% endif %}
diff --git a/app/utils/api_health.py b/app/utils/api_health.py new file mode 100644 index 000000000..c75fef5da --- /dev/null +++ b/app/utils/api_health.py @@ -0,0 +1,13 @@ +import os + +import requests +from requests.exceptions import RequestException + + +def is_api_down(): + api_base_url = os.getenv("API_BASE_URL", "http://localhost:6011") + try: + response = requests.get(api_base_url, timeout=2) + return response.status_code != 200 + except RequestException: + return True diff --git a/notifications_utils/markdown.py b/notifications_utils/markdown.py index 43e7059b2..57d35ba43 100644 --- a/notifications_utils/markdown.py +++ b/notifications_utils/markdown.py @@ -1,8 +1,10 @@ -from flask import current_app -import mistune -from notifications_utils.formatters import create_sanitised_html_for_url -import re import html +import re + +import mistune +from flask import current_app + +from notifications_utils.formatters import create_sanitised_html_for_url LINK_STYLE = "word-wrap: break-word; color: #1D70B8;" From 77e9475ed80c8c9be9c9e2f670b4eb1b71216354 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 17 Apr 2025 15:04:50 -0700 Subject: [PATCH 2/2] fixing templates --- app/templates/error/technical_difficulties.html | 11 +++++++++-- app/templates/views/signedout.html | 11 ----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/templates/error/technical_difficulties.html b/app/templates/error/technical_difficulties.html index af6a4401d..cdb09e074 100644 --- a/app/templates/error/technical_difficulties.html +++ b/app/templates/error/technical_difficulties.html @@ -1,4 +1,12 @@ -{% block content %} +
+
+
+

+ We're currently having some technical issues. We're working on it and will be back soon. Thanks for your patience! +

+
+
+
@@ -16,4 +24,3 @@
-{% endblock %} diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index 624874c10..b95cb7e82 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -12,17 +12,6 @@ import usaButton %} {% block meta %} {% block beforeContent %}{% endblock %}
- {% if is_api_down %} -
-
-
-

- We're currently having some technical issues. We're working on it and will be back soon. Thanks for your patience! -

-
-
-
- {% endif %} {% block content %} {% if is_api_down %} {% include "error/technical_difficulties.html" %}