From cab6e5ec343f51fccf97a6a5ffd2634582766d0b Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 3 Apr 2025 17:55:58 +0200 Subject: [PATCH] Refactor errors a bit --- src/anonchat/__init__.py | 4 ++-- src/anonchat/error_handlers.py | 2 +- src/anonchat/templates/error.html | 7 ++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/anonchat/__init__.py b/src/anonchat/__init__.py index c1f9775..eced8f7 100644 --- a/src/anonchat/__init__.py +++ b/src/anonchat/__init__.py @@ -96,8 +96,8 @@ with app.app_context(): def health_check(): return jsonify(status="healthy"), 200 -from . import error_handlers - +from .error_handlers import register_error_handlers +register_error_handlers(app) # Import routes from . import routes diff --git a/src/anonchat/error_handlers.py b/src/anonchat/error_handlers.py index 752be3d..2fa3d6e 100644 --- a/src/anonchat/error_handlers.py +++ b/src/anonchat/error_handlers.py @@ -24,4 +24,4 @@ def register_error_handlers(app): if request.is_json or request.headers.get('X-Requested-With') == 'XMLHttpRequest': return jsonify(error=title, message=message), status_code else: - return render_template('error.html', title=title, message=message), status_code \ No newline at end of file + return render_template('error.html', title=title, message=message, status_code=status_code), status_code \ No newline at end of file diff --git a/src/anonchat/templates/error.html b/src/anonchat/templates/error.html index 2e54cc4..c514a71 100644 --- a/src/anonchat/templates/error.html +++ b/src/anonchat/templates/error.html @@ -2,13 +2,10 @@ {% block title %}{{ title }}{% endblock %} -{% block header %} -

{{ title }}

-{% endblock %} - {% block content %}
-
Error
+
{{ status_code | default("Error") }}
+

{{ title }}

{{ message }}