Show friendly error page when a service is unavailable
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m21s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m21s
FragmentError now renders a 503 page naming which service is down instead of a generic 500 error. Helps debug during deploys. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ from quart import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
|
from shared.infrastructure.fragments import FragmentError as _FragmentError
|
||||||
|
|
||||||
class AppError(ValueError):
|
class AppError(ValueError):
|
||||||
"""
|
"""
|
||||||
@@ -107,6 +108,23 @@ def errors(app):
|
|||||||
)
|
)
|
||||||
return await make_response(html, status)
|
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"<p class='text-sm text-red-600'>Service <b>{escape(service)}</b> is unavailable.</p>",
|
||||||
|
503,
|
||||||
|
)
|
||||||
|
html = await render_template(
|
||||||
|
"_types/root/exceptions/error.html",
|
||||||
|
service_name=service,
|
||||||
|
)
|
||||||
|
return await make_response(html, 503)
|
||||||
|
|
||||||
@app.errorhandler(Exception)
|
@app.errorhandler(Exception)
|
||||||
async def error(e):
|
async def error(e):
|
||||||
current_app.logger.exception("Exception %s", _info(e))
|
current_app.logger.exception("Exception %s", _info(e))
|
||||||
|
|||||||
@@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
{% block error_summary %}
|
{% block error_summary %}
|
||||||
<div>
|
<div>
|
||||||
WELL THIS IS EMBARASSING...
|
{% if service_name %}
|
||||||
|
The <b>{{ service_name }}</b> service is currently unavailable. It may be restarting.
|
||||||
|
{% else %}
|
||||||
|
WELL THIS IS EMBARASSING...
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user