diff --git a/shared/browser/app/errors.py b/shared/browser/app/errors.py index bb8cdf2..0da2550 100644 --- a/shared/browser/app/errors.py +++ b/shared/browser/app/errors.py @@ -9,6 +9,7 @@ from quart import ( ) from markupsafe import escape +from shared.infrastructure.fragments import FragmentError as _FragmentError class AppError(ValueError): """ @@ -107,6 +108,23 @@ def errors(app): ) return await make_response(html, status) + @app.errorhandler(_FragmentError) + async def fragment_error(e): + current_app.logger.error("FragmentError %s", _info(e)) + msg = str(e) + # Extract service name from "Fragment account/auth-menu failed: ..." + service = msg.split("/")[0].replace("Fragment ", "") if "/" in msg else "unknown" + if request.headers.get("HX-Request") == "true": + return await make_response( + f"

Service {escape(service)} is unavailable.

", + 503, + ) + html = await render_template( + "_types/root/exceptions/error.html", + service_name=service, + ) + return await make_response(html, 503) + @app.errorhandler(Exception) async def error(e): current_app.logger.exception("Exception %s", _info(e)) diff --git a/shared/browser/templates/_types/root/exceptions/error.html b/shared/browser/templates/_types/root/exceptions/error.html index 70a8164..405ffc8 100644 --- a/shared/browser/templates/_types/root/exceptions/error.html +++ b/shared/browser/templates/_types/root/exceptions/error.html @@ -2,7 +2,11 @@ {% block error_summary %}
- WELL THIS IS EMBARASSING... + {% if service_name %} + The {{ service_name }} service is currently unavailable. It may be restarting. + {% else %} + WELL THIS IS EMBARASSING... + {% endif %}
{% endblock %}