aboutsummaryrefslogtreecommitdiff
path: root/gn3/errors.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-01-28 03:13:28 +0300
committerFrederick Muriuki Muriithi2023-01-28 03:20:01 +0300
commite6e173b74d381f590ff5a8e7957489ea4d50c06b (patch)
tree0f411a2b8d201a50bcdaf9684d37010bd047c3ef /gn3/errors.py
parent9f8de83700a5aa1c19ec8d11b0978e8852b442db (diff)
downloadgenenetwork3-e6e173b74d381f590ff5a8e7957489ea4d50c06b.tar.gz
auth: Store error_code in Exception for flexibility
To allow for different error codes for the various exceptions, store the error_code in the exception objects and retrieve it from there when generating the response.
Diffstat (limited to 'gn3/errors.py')
-rw-r--r--gn3/errors.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/gn3/errors.py b/gn3/errors.py
index 01f917e..4d41dc3 100644
--- a/gn3/errors.py
+++ b/gn3/errors.py
@@ -1,14 +1,15 @@
"""Handle application level errors."""
-from flask import Flask, jsonify
+from flask import Flask, jsonify, current_app
from gn3.auth.authorisation.errors import AuthorisationError
def handle_authorisation_error(exc: AuthorisationError):
"""Handle AuthorisationError if not handled anywhere else."""
+ current_app.logger.error(exc)
return jsonify({
"error": type(exc).__name__,
"error_description": " :: ".join(exc.args)
- }), 500
+ }), exc.error_code
def register_error_handlers(app: Flask):
"""Register application-level error handlers."""