diff options
Diffstat (limited to 'qc_app')
-rw-r--r-- | qc_app/__init__.py | 3 | ||||
-rw-r--r-- | qc_app/errors.py | 14 | ||||
-rw-r--r-- | qc_app/templates/unhandled_exception.html | 21 |
3 files changed, 38 insertions, 0 deletions
diff --git a/qc_app/__init__.py b/qc_app/__init__.py index 6b760b9..4810d45 100644 --- a/qc_app/__init__.py +++ b/qc_app/__init__.py @@ -7,6 +7,7 @@ from flask import Flask from .entry import entrybp from .parse import parsebp from .dbinsert import dbinsertbp +from .errors import register_error_handlers def instance_path(): """Retrieve the `instance_path`. Raise an exception if not defined.""" @@ -29,4 +30,6 @@ def create_app(instance_dir): app.register_blueprint(entrybp, url_prefix="/") app.register_blueprint(parsebp, url_prefix="/parse") app.register_blueprint(dbinsertbp, url_prefix="/dbinsert") + + register_error_handlers(app) return app 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) diff --git a/qc_app/templates/unhandled_exception.html b/qc_app/templates/unhandled_exception.html new file mode 100644 index 0000000..6e6a051 --- /dev/null +++ b/qc_app/templates/unhandled_exception.html @@ -0,0 +1,21 @@ +{%extends "base.html"%} + +{%block title%}System Error{%endblock%} + +{%block css%} +<link rel="stylesheet" href="/static/css/two-column-with-separator.css" /> +{%endblock%} + +{%block contents%} +<p> + An error has occured, and your request has been aborted. Please notify the + administrator to try and get this sorted. +</p> +<p> + Provide the following information to help the administrator figure out and fix + the issue:<br /> + <hr /><br /> + {{trace}} + <hr /><br /> +</p> +{%endblock%} |