From 3752c663fa9ded1801680aa2342947b7676d8ce9 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 4 Jan 2023 11:20:30 +0300 Subject: auth: Add `/register-user` endpoint * gn3/app.py: register top-level error handlers. reorganise oauth2 blueprint. * gn3/auth/__init__.py: reorganise oaut2 blueprint. * gn3/auth/authentication/oauth2/views.py: reorganise oauth2 blueprint. * gn3/auth/authorisation/exceptions.py -> gn3/auth/authorisation/errors.py * gn3/auth/authorisation/groups.py: rename file/module * gn3/auth/authorisation/resources.py: rename file/module * gn3/auth/authorisation/views.py: Add `/register-user` endpoint * gn3/auth/blueprint.py: reorganise oauth2 blueprint. * gn3/errors.py: register top-level error handlers. --- gn3/errors.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 gn3/errors.py (limited to 'gn3/errors.py') diff --git a/gn3/errors.py b/gn3/errors.py new file mode 100644 index 0000000..01f917e --- /dev/null +++ b/gn3/errors.py @@ -0,0 +1,15 @@ +"""Handle application level errors.""" +from flask import Flask, jsonify + +from gn3.auth.authorisation.errors import AuthorisationError + +def handle_authorisation_error(exc: AuthorisationError): + """Handle AuthorisationError if not handled anywhere else.""" + return jsonify({ + "error": type(exc).__name__, + "error_description": " :: ".join(exc.args) + }), 500 + +def register_error_handlers(app: Flask): + """Register application-level error handlers.""" + app.register_error_handler(AuthorisationError, handle_authorisation_error) -- cgit v1.2.3