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