From 314a095264f47b8aecfc01d20beca4f35ab9121a Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 28 Feb 2024 11:55:15 +0300 Subject: Handle the "NotFoundError" exception at the route level Handle the "NotFoundError" exception at the route level, since if we do not, the application level handler takes over and simply returns a JSON response with the details of the failure. --- gn_auth/auth/authorisation/users/admin/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gn_auth/auth/authorisation/users') diff --git a/gn_auth/auth/authorisation/users/admin/views.py b/gn_auth/auth/authorisation/users/admin/views.py index 6ace0e5..aed8b31 100644 --- a/gn_auth/auth/authorisation/users/admin/views.py +++ b/gn_auth/auth/authorisation/users/admin/views.py @@ -18,6 +18,8 @@ from flask import ( from gn_auth import session +from gn_auth.auth.authorisation.errors import NotFoundError + from ....db import sqlite3 as db from ....db.sqlite3 import with_db_connection @@ -77,8 +79,10 @@ def login(): expires=( datetime.now(tz=timezone.utc) + timedelta(minutes=10))) return redirect(url_for(next_uri)) - flash(error_message, "alert-danger") - return login_page + raise NotFoundError(error_message) + except NotFoundError as _nfe: + flash(error_message, "alert-danger") + return login_page except EmailNotValidError as _enve: flash(error_message, "alert-danger") return login_page -- cgit v1.2.3