diff options
Diffstat (limited to 'gn_auth/errors.py')
-rw-r--r-- | gn_auth/errors.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/gn_auth/errors.py b/gn_auth/errors.py index d50d7c1..4b6007a 100644 --- a/gn_auth/errors.py +++ b/gn_auth/errors.py @@ -8,7 +8,9 @@ from gn_auth.auth.errors import AuthorisationError def add_trace(exc: Exception, errobj: dict) -> dict: """Add the traceback to the error handling object.""" - current_app.logger.debug(traceback.format_exception(exc)) + current_app.logger.error("Endpoint: %s\n%s", + request.url, + traceback.format_exception(exc)) return { **errobj, "error-trace": "".join(traceback.format_exception(exc)) @@ -16,6 +18,7 @@ def add_trace(exc: Exception, errobj: dict) -> dict: def page_not_found(exc): """404 handler.""" + current_app.logger.error(f"Page '{request.url}' was not found.", exc_info=True) content_type = request.content_type if bool(content_type) and content_type.lower() == "application/json": return jsonify(add_trace(exc, { @@ -28,20 +31,27 @@ def page_not_found(exc): def handle_general_exception(exc: Exception): + """Handle generic unhandled exceptions.""" + current_app.logger.error("Error occurred!", exc_info=True) content_type = request.content_type if bool(content_type) and content_type.lower() == "application/json": + exc_args = [str(x) for x in exc.args] msg = ("The following exception was raised while attempting to access " - f"{request.url}: {exc.args[0]}") + f"{request.url}: {' '.join(exc_args)}") return jsonify(add_trace(exc, { "error": type(exc).__name__, "error_description": msg })), 500 - return render_template("500.html", page=request.url), 500 + return render_template("50x.html", + page=request.url, + error=exc, + trace=traceback.format_exception(exc)), 500 def handle_authorisation_error(exc: AuthorisationError): """Handle AuthorisationError if not handled anywhere else.""" + current_app.logger.error("Error occurred!", exc_info=True) current_app.logger.error(exc) return jsonify(add_trace(exc, { "error": type(exc).__name__, |