aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/auth/db.py1
-rw-r--r--gn3/errors.py12
2 files changed, 12 insertions, 1 deletions
diff --git a/gn3/auth/db.py b/gn3/auth/db.py
index b8c91e9..9d5463f 100644
--- a/gn3/auth/db.py
+++ b/gn3/auth/db.py
@@ -48,6 +48,7 @@ class DbCursor(Protocol):
@contextlib.contextmanager
def connection(db_path: str, row_factory: Callable = sqlite3.Row) -> Iterator[DbConnection]:
"""Create the connection to the auth database."""
+ logging.debug(f"SQLite3 DB Path: '{db_path}'.")
conn = sqlite3.connect(db_path)
conn.row_factory = row_factory
conn.set_trace_callback(logging.debug)
diff --git a/gn3/errors.py b/gn3/errors.py
index 606b3d3..f9b3c02 100644
--- a/gn3/errors.py
+++ b/gn3/errors.py
@@ -1,4 +1,5 @@
"""Handle application level errors."""
+from sqlite3 import OperationalError
from flask import Flask, jsonify, current_app
from authlib.oauth2.rfc6749.errors import OAuth2Error
@@ -20,7 +21,16 @@ def handle_oauth2_errors(exc: OAuth2Error):
"error_description": exc.description,
}), exc.status_code
+def handle_sqlite3_errors(exc: OperationalError):
+ """Handle sqlite3 errors if not handled anywhere else."""
+ current_app.logger.error(exc)
+ return jsonify({
+ "error": "DatabaseError",
+ "error_description": exc.args[0],
+ }), 500
+
def register_error_handlers(app: Flask):
"""Register application-level error handlers."""
- app.register_error_handler(AuthorisationError, handle_authorisation_error)
app.register_error_handler(OAuth2Error, handle_oauth2_errors)
+ app.register_error_handler(OperationalError, handle_sqlite3_errors)
+ app.register_error_handler(AuthorisationError, handle_authorisation_error)