From a46ad1d468fe5ace7a4503693e2e4d404f87ebf3 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 14 Apr 2023 08:46:26 +0300 Subject: Handle errors for group consistent with the UI. --- wqflask/wqflask/oauth2/groups.py | 8 ++++++-- wqflask/wqflask/oauth2/request_utils.py | 5 +++-- wqflask/wqflask/templates/oauth2/group.html | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/wqflask/wqflask/oauth2/groups.py b/wqflask/wqflask/oauth2/groups.py index 551c0640..3bc5fb6d 100644 --- a/wqflask/wqflask/oauth2/groups.py +++ b/wqflask/wqflask/oauth2/groups.py @@ -9,7 +9,7 @@ from flask import ( from .checks import require_oauth2 from .client import oauth2_get, oauth2_post from .request_utils import ( - user_details, handle_error, request_error, process_error, handle_success, + user_details, handle_error, process_error, handle_success, raise_unimplemented) groups = Blueprint("group", __name__) @@ -32,8 +32,12 @@ def user_group(): user_error=process_error(error)), partial(__get_join_requests__, group)) + def __group_error__(err): + return render_template( + "oauth2/group.html", group_error=process_error(err)) + return oauth2_get("oauth2/user/group").either( - request_error, __success__) + __group_error__, __success__) @groups.route("/create", methods=["POST"]) @require_oauth2 diff --git a/wqflask/wqflask/oauth2/request_utils.py b/wqflask/wqflask/oauth2/request_utils.py index eefae900..fae3a347 100644 --- a/wqflask/wqflask/oauth2/request_utils.py +++ b/wqflask/wqflask/oauth2/request_utils.py @@ -20,10 +20,11 @@ def process_error(error: Response, "server.") ) -> dict: if error.status_code == 404: + msg = error.json()["error_description"] if hasattr(error, "json") else message return { "error": "NotFoundError", - "error_message": message, - "error_description": message, + "error_message": msg, + "error_description": msg, "status_code": error.status_code } return {**error.json(), "status_code": error.status_code} diff --git a/wqflask/wqflask/templates/oauth2/group.html b/wqflask/wqflask/templates/oauth2/group.html index a6a3e6c3..a2380df7 100644 --- a/wqflask/wqflask/templates/oauth2/group.html +++ b/wqflask/wqflask/templates/oauth2/group.html @@ -8,6 +8,11 @@ {{flash_me()}} + {%if group_error is defined%} +
+ {{display_error("Group", group_error)}} +
+ {%else%}
{%if group_join_requests_error is defined %} @@ -103,6 +108,7 @@
+ {%endif%}
{%endblock%} -- cgit v1.2.3