about summary refs log tree commit diff
path: root/gn3/errors.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/errors.py')
-rw-r--r--gn3/errors.py50
1 files changed, 31 insertions, 19 deletions
diff --git a/gn3/errors.py b/gn3/errors.py
index b54fecd..e46ce24 100644
--- a/gn3/errors.py
+++ b/gn3/errors.py
@@ -13,7 +13,7 @@ from SPARQLWrapper.SPARQLExceptions import (
     Unauthorized
 )
 from werkzeug.exceptions import NotFound
-from flask import Flask, jsonify, Response
+from flask import Flask, request, jsonify, Response
 from authlib.oauth2.rfc6749.errors import OAuth2Error
 
 from gn3.oauth2 import errors as oautherrors
@@ -33,34 +33,43 @@ def add_trace(exc: Exception, jsonmsg: dict) -> dict:
 
 def page_not_found(pnf):
     """Generic 404 handler."""
-    logger.error("Handling 404 errors", exc_info=True)
+    logger.error("Handling 404 errors - %s - %s - %s",
+                 pnf.name,
+                 pnf.description,
+                 request.url)
     return jsonify(add_trace(pnf, {
         "error": pnf.name,
         "error_description": pnf.description
     })), 404
 
 
-def internal_server_error(pnf):
+def internal_server_error(ise):
     """Generic 404 handler."""
-    logger.error("Handling internal server errors", exc_info=True)
-    return jsonify(add_trace(pnf, {
-        "error": pnf.name,
-        "error_description": pnf.description
+    logger.error("Handling internal server errors - %s - %s - %s",
+                 ise.name,
+                 ise.description,
+                 request.url)
+    return jsonify(add_trace(ise, {
+        "error": ise.name,
+        "error_description": ise.description
     })), 500
 
 
-def url_server_error(pnf):
+def url_server_error(urlse):
     """Handler for an exception with a url connection."""
-    logger.error("Handling url server errors", exc_info=True)
-    return jsonify(add_trace(pnf, {
-        "error": f"URLLib Error no: {pnf.reason.errno}",
-        "error_description": pnf.reason.strerror,
+    logger.error("Handling url server errors - %s - %s - %s",
+                 urlse.name,
+                 urlse.description,
+                 request.url)
+    return jsonify(add_trace(urlse, {
+        "error": f"URLLib Error no: {urlse.reason.errno}",
+        "error_description": urlse.reason.strerror,
     })), 500
 
 
 def handle_authorisation_error(exc: AuthorisationError):
     """Handle AuthorisationError if not handled anywhere else."""
-    logger.error("Handling external auth errors", exc_info=True)
+    logger.error("Handling external auth errors - %s", request.url)
     return jsonify(add_trace(exc, {
         "error": type(exc).__name__,
         "error_description": " :: ".join(exc.args)
@@ -69,7 +78,10 @@ def handle_authorisation_error(exc: AuthorisationError):
 
 def handle_oauth2_errors(exc: OAuth2Error):
     """Handle OAuth2Error if not handled anywhere else."""
-    logger.error("Handling external oauth2 errors", exc_info=True)
+    logger.error("Handling external oauth2 errors - %s - %s -%s",
+                 exc.error,
+                 exc.description,
+                 request.url)
     return jsonify(add_trace(exc, {
         "error": exc.error,
         "error_description": exc.description,
@@ -78,7 +90,7 @@ def handle_oauth2_errors(exc: OAuth2Error):
 
 def handle_sqlite3_errors(exc: OperationalError):
     """Handle sqlite3 errors if not handled anywhere else."""
-    logger.error("Handling sqlite3 errors", exc_info=True)
+    logger.error("Handling sqlite3 errors: %s", request.url)
     return jsonify({
         "error": "DatabaseError",
         "error_description": exc.args[0],
@@ -87,7 +99,7 @@ def handle_sqlite3_errors(exc: OperationalError):
 
 def handle_sparql_errors(exc):
     """Handle sparql/virtuoso errors if not handled anywhere else."""
-    logger.error("Handling sparql errors", exc_info=True)
+    logger.error("Handling sparql errors: %s", request.url)
     code = {
         "EndPointInternalError": 500,
         "EndPointNotFound": 404,
@@ -102,7 +114,7 @@ def handle_sparql_errors(exc):
 
 def handle_generic(exc: Exception) -> Response:
     """Handle generic exception."""
-    logger.error("Handling generic errors", exc_info=True)
+    logger.error("Handling generic errors - %s", request.url)
     resp = jsonify({
         "error": type(exc).__name__,
         "error_description": (
@@ -115,7 +127,7 @@ def handle_generic(exc: Exception) -> Response:
 
 def handle_local_authorisation_errors(exc: oautherrors.AuthorisationError):
     """Handle errors relating to authorisation that are raised locally."""
-    logger.error("Handling local auth errors", exc_info=True)
+    logger.error("Handling local auth errors - %s", request.url)
     return jsonify(add_trace(exc, {
         "error": type(exc).__name__,
         "error_description": " ".join(exc.args)
@@ -124,7 +136,7 @@ def handle_local_authorisation_errors(exc: oautherrors.AuthorisationError):
 
 def handle_llm_error(exc: Exception) -> Response:
     """ Handle llm erros if not handled  anywhere else. """
-    logger.error(exc)
+    logger.error("Handling LLM errors - %s", request.url)
     resp = jsonify({
         "query": exc.args[1],
         "error_type": type(exc).__name__,