aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-10-19 09:03:52 +0300
committerFrederick Muriuki Muriithi2023-10-19 09:10:00 +0300
commit6e16566c0bfb81561104f4db6934b6d216ed4fe7 (patch)
tree18f2f194df15e67794bfa17bea931504284ef92e /gn3
parent0a7c9c8f5a329321f4bac9bcabaa160b5f6b12aa (diff)
downloadgenenetwork3-6e16566c0bfb81561104f4db6934b6d216ed4fe7.tar.gz
Handle 404 error(s) at top level.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/errors.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/gn3/errors.py b/gn3/errors.py
index f9b3c02..121187c 100644
--- a/gn3/errors.py
+++ b/gn3/errors.py
@@ -5,6 +5,12 @@ from authlib.oauth2.rfc6749.errors import OAuth2Error
from gn3.auth.authorisation.errors import AuthorisationError
+def page_not_found(pnf):
+ return jsonify({
+ "error": pnf.name,
+ "error_description": pnf.description
+ }), 404
+
def handle_authorisation_error(exc: AuthorisationError):
"""Handle AuthorisationError if not handled anywhere else."""
current_app.logger.error(exc)
@@ -31,6 +37,7 @@ def handle_sqlite3_errors(exc: OperationalError):
def register_error_handlers(app: Flask):
"""Register application-level error handlers."""
+ app.register_error_handler(404, page_not_found)
app.register_error_handler(OAuth2Error, handle_oauth2_errors)
app.register_error_handler(OperationalError, handle_sqlite3_errors)
app.register_error_handler(AuthorisationError, handle_authorisation_error)