aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-08-01 14:57:45 -0500
committerFrederick Muriuki Muriithi2024-08-01 14:59:24 -0500
commit8d16ba00c2ad3fc1e94c2f5f74bde5145263408f (patch)
tree6b9d2ff10ce7c7bbc698f8564c23013d3f5d6e5d /gn3
parent025eaca42fc74fc7ed5793e9eb4959c42c1b61c9 (diff)
downloadgenenetwork3-8d16ba00c2ad3fc1e94c2f5f74bde5145263408f.tar.gz
Add handler for unhandled exceptions from `gn3.oauth2` module.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/errors.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/gn3/errors.py b/gn3/errors.py
index 1833bf6..42b5788 100644
--- a/gn3/errors.py
+++ b/gn3/errors.py
@@ -15,6 +15,7 @@ from werkzeug.exceptions import NotFound
from authlib.oauth2.rfc6749.errors import OAuth2Error
from flask import Flask, jsonify, Response, current_app
+from gn3.oauth2 import errors as oautherrors
from gn3.auth.authorisation.errors import AuthorisationError
@@ -106,6 +107,15 @@ def handle_generic(exc: Exception) -> Response:
return resp
+def handle_local_authorisation_errors(exc: oautherrors.AuthorisationError):
+ """Handle errors relating to authorisation that are raised locally."""
+ current_app.logger.error("Handling local auth errors", exc_info=True)
+ return jsonify(add_trace(exc, {
+ "error": type(exc).__name__,
+ "error_description": " ".join(exc.args)
+ })), 400
+
+
def register_error_handlers(app: Flask):
"""Register application-level error handlers."""
app.register_error_handler(NotFound, page_not_found)