diff --git a/src/howitz/__init__.py b/src/howitz/__init__.py index 912d398..f194f0b 100644 --- a/src/howitz/__init__.py +++ b/src/howitz/__init__.py @@ -13,7 +13,7 @@ from howitz.config.utils import load_config from howitz.config.zino1 import make_zino1_config from howitz.config.howitz import make_howitz_config -from howitz.error_handlers import handle_generic_exception, handle_generic_http_exception, handle_400, handle_404, handle_403, handle_lost_connection +from howitz.error_handlers import handle_generic_exception, handle_generic_http_exception, handle_400, handle_404, handle_403, handle_lost_connection, handle_bad_gateway from howitz.users.db import UserDB from howitz.users.commands import user_cli from zinolib.controllers.zino1 import Zino1EventManager, LostConnectionError, NotConnectedError @@ -33,6 +33,7 @@ def create_app(test_config=None): app.register_error_handler(LostConnectionError, handle_lost_connection) app.register_error_handler(BrokenPipeError, handle_lost_connection) app.register_error_handler(NotConnectedError, handle_lost_connection) + app.register_error_handler(502, handle_bad_gateway) # load config app = load_config(app, test_config) diff --git a/src/howitz/error_handlers.py b/src/howitz/error_handlers.py index 43a24eb..43e91de 100644 --- a/src/howitz/error_handlers.py +++ b/src/howitz/error_handlers.py @@ -2,7 +2,7 @@ from flask import render_template, session, current_app, make_response, request from flask_login import current_user -from werkzeug.exceptions import HTTPException +from werkzeug.exceptions import HTTPException, BadGateway from howitz.endpoints import connect_to_zino from howitz.utils import serialize_exception @@ -79,6 +79,20 @@ def handle_403(e): return response, 403 +def handle_bad_gateway(e): + current_app.logger.exception("502 Bad Gateway has occurred %s", e) + description = BadGateway.description + try: + description = e.description + except AttributeError: + pass + + response = make_response(render_template('responses/502.html', err_msg=description)) + response.headers['HX-Retarget'] = 'body' + response.headers['HX-Reswap'] = 'innerHTML' + return response, 502 + + def handle_lost_connection(e): if isinstance(e, BrokenPipeError): current_app.logger.exception("Lost connection to Zino server: %s", e) diff --git a/src/howitz/templates/responses/502.html b/src/howitz/templates/responses/502.html new file mode 100644 index 0000000..bbb5310 --- /dev/null +++ b/src/howitz/templates/responses/502.html @@ -0,0 +1,11 @@ +{% block content %} +
+
+

502

+

Bad Gateway

+

{{ err_msg }}

+
+
+{% endblock %}