aboutsummaryrefslogtreecommitdiff
path: root/qc_app/errors.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-11-28 15:36:28 +0300
committerFrederick Muriuki Muriithi2023-11-28 16:33:22 +0300
commitc1dcd4f20e3e0e89d7e2dce051526d2db36f9579 (patch)
tree517b6d2db014dae6de5ad973477aec338890f080 /qc_app/errors.py
parentc213b0010c3ddc8d3215adab65bd489a9b884e30 (diff)
downloadgn-uploader-c1dcd4f20e3e0e89d7e2dce051526d2db36f9579.tar.gz
Capture, log and handle generic exceptions
Handle any and all unforeseen error conditions gracefully by capturing the exceptions, logging out for debug purposes and providing the user with a generic error page.
Diffstat (limited to 'qc_app/errors.py')
-rw-r--r--qc_app/errors.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/qc_app/errors.py b/qc_app/errors.py
new file mode 100644
index 0000000..0da6b3c
--- /dev/null
+++ b/qc_app/errors.py
@@ -0,0 +1,14 @@
+"""Application error handling."""
+import logging
+import traceback
+
+from flask import Flask, render_template
+
+def handle_general_exception(exc: Exception):
+ trace = traceback.format_exc()
+ logging.error("Error: Generic unhandled exception!!\n%s", trace)
+ return render_template("unhandled_exception.html", trace=trace)
+
+def register_error_handlers(app: Flask):
+ """Register top-level error/exception handlers."""
+ app.register_error_handler(Exception, handle_general_exception)