From 8d16ba00c2ad3fc1e94c2f5f74bde5145263408f Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 1 Aug 2024 14:57:45 -0500 Subject: Add handler for unhandled exceptions from `gn3.oauth2` module. --- gn3/errors.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) -- cgit v1.2.3