aboutsummaryrefslogtreecommitdiff
path: root/gn3/errors.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/errors.py')
-rw-r--r--gn3/errors.py12
1 files changed, 11 insertions, 1 deletions
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)