aboutsummaryrefslogtreecommitdiff
path: root/gn3/errors.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/errors.py')
-rw-r--r--gn3/errors.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/gn3/errors.py b/gn3/errors.py
index 4d41dc3..7ae07f4 100644
--- a/gn3/errors.py
+++ b/gn3/errors.py
@@ -1,5 +1,6 @@
"""Handle application level errors."""
from flask import Flask, jsonify, current_app
+from authlib.oauth2.rfc6749.errors import OAuth2Error
from gn3.auth.authorisation.errors import AuthorisationError
@@ -11,6 +12,14 @@ def handle_authorisation_error(exc: AuthorisationError):
"error_description": " :: ".join(exc.args)
}), exc.error_code
+def handle_oauth2_errors(exc: OAuth2Error):
+ current_app.logger.error(exc)
+ return jsonify({
+ "error": exc.error,
+ "error_description": exc.description,
+ }), exc.status_code
+
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)