From 20f89d1e52a7fc7cd85c6956ea1df801a98e3277 Mon Sep 17 00:00:00 2001
From: Jan Mach <jan.mach@cesnet.cz>
Date: Thu, 20 Feb 2020 20:18:03 +0100
Subject: [PATCH] Added logging or request.path_full to enable better debugging
 of BAD REQUEST and INTERNAL SERVER ERROR errors.

---
 lib/hawat/app.py  | 8 +++++---
 lib/hawat/base.py | 8 ++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/hawat/app.py b/lib/hawat/app.py
index 16f6cf7bb..1d1152492 100644
--- a/lib/hawat/app.py
+++ b/lib/hawat/app.py
@@ -191,7 +191,8 @@ def _setup_app_core(app):
     def eh_badrequest(err):  # pylint: disable=locally-disabled,unused-variable
         """Flask error handler to be called to service HTTP 400 error."""
         flask.current_app.logger.critical(
-            "Bad Request Error:\n%s",
+            "BAD REQUEST\n\nRequest: %s\nTraceback:\n%s",
+            flask.request.full_path,
             ''.join(
                 traceback.TracebackException(
                     *sys.exc_info()
@@ -224,12 +225,13 @@ def _setup_app_core(app):
     def eh_internal_server_error(err):  # pylint: disable=locally-disabled,unused-variable
         """Flask error handler to be called to service HTTP 500 error."""
         flask.current_app.logger.critical(
-            "Internal Server Error:\n%s",
+            "INTERNAL SERVER ERROR\n\nRequest: %s\nTraceback:\n%s",
+            flask.request.full_path,
             ''.join(
                 traceback.TracebackException(
                     *sys.exc_info()
                 ).format()
-            )
+            ),
         )
         return hawat.errors.error_handler_switch(500, err)
 
diff --git a/lib/hawat/base.py b/lib/hawat/base.py
index 5ce49b5fc..87ee99c1f 100644
--- a/lib/hawat/base.py
+++ b/lib/hawat/base.py
@@ -302,6 +302,14 @@ class HawatApp(flask.Flask):
             else:
                 raise HawatAppException("Invalid blueprint module '{}', does not provide the 'get_blueprint' factory method.".format(name))
 
+    def log_exception(self, exc_info):
+        """
+        Reimplementation of :py:func:`flask.Flask.log_exception` method.
+        """
+        self.logger.error(
+            "Exception on %s [%s]" % (flask.request.path_full, request.method), exc_info=exc_info
+        )
+
     def log_exception_with_label(self, tbexc, label = ''):
         """
         Log given exception traceback into application logger.
-- 
GitLab