From 6e16566c0bfb81561104f4db6934b6d216ed4fe7 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 19 Oct 2023 09:03:52 +0300 Subject: Handle 404 error(s) at top level. --- gn3/errors.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gn3') 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) -- cgit v1.2.3