aboutsummaryrefslogtreecommitdiff
path: root/qc_app
diff options
context:
space:
mode:
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/errors.py11
-rw-r--r--qc_app/templates/http-error.html18
2 files changed, 28 insertions, 1 deletions
diff --git a/qc_app/errors.py b/qc_app/errors.py
index 1ce0d1f..bcd3543 100644
--- a/qc_app/errors.py
+++ b/qc_app/errors.py
@@ -13,8 +13,17 @@ def handle_general_exception(exc: Exception):
exc.__class__.__module__, exc.__class__.__name__, request.url, trace)
return render_template("unhandled_exception.html", trace=trace)
+def handle_http_exception(exc: HTTPException):
+ """Handle HTTP exceptions."""
+ app.logger.error(
+ "HTTP Error %s: %s", exc.code, exc.description, exc_info=True)
+ return render_template(f"http-error.html",
+ request_url=request.url,
+ exc=exc,
+ trace=traceback.format_exception(exc)), exc.code
+
def register_error_handlers(appl: Flask):
"""Register top-level error/exception handlers."""
appl.register_error_handler(Exception, handle_general_exception)
- appl.register_error_handler(HTTPException, handle_general_exception)
+ appl.register_error_handler(HTTPException, handle_http_exception)
appl.register_error_handler(mdb.MySQLError, handle_general_exception)
diff --git a/qc_app/templates/http-error.html b/qc_app/templates/http-error.html
new file mode 100644
index 0000000..6a74ae8
--- /dev/null
+++ b/qc_app/templates/http-error.html
@@ -0,0 +1,18 @@
+{%extends "base.html"%}
+
+{%block title%}HTTP Error: {{exc.code}}{%endblock%}
+
+{%block contents%}
+<h1>{{exc.code}}: {{exc.description}}</h1>
+
+<div class="row">
+ <p>
+ You attempted to access {{request_url}} which failed with the following
+ error:
+ </p>
+</div>
+
+<div class="row">
+ <pre>{{trace}}</pre>
+</div>
+{%endblock%}