about summary refs log tree commit diff
path: root/qc_app/errors.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-06-13 15:04:28 -0500
committerFrederick Muriuki Muriithi2024-06-13 15:04:28 -0500
commit68a43dc318fb7d76544d704752f243b9afed7e52 (patch)
tree31d2fd165058a7296bc44567a4a388ab5280d946 /qc_app/errors.py
parent31fb2794ffd4b17be35a2e122a8c6605aebaf65b (diff)
downloadgn-uploader-68a43dc318fb7d76544d704752f243b9afed7e52.tar.gz
Handle HTTP errors gracefully.
Diffstat (limited to 'qc_app/errors.py')
-rw-r--r--qc_app/errors.py11
1 files changed, 10 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)