From 4812b01e72944e3aa35fc92cce5e5f560d448322 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Mon, 11 Dec 2023 15:08:49 +0100 Subject: [PATCH 1/3] Fix handling of non compliant error responses --- zgw_consumers/admin_fields.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/zgw_consumers/admin_fields.py b/zgw_consumers/admin_fields.py index 5537ae1..bcef383 100644 --- a/zgw_consumers/admin_fields.py +++ b/zgw_consumers/admin_fields.py @@ -51,9 +51,13 @@ def get_zaaktype_field(db_field: Field, request: HttpRequest, **kwargs): zaaktypen = get_zaaktypen() except ClientError as exc: error_message = exc.args[0] - messages.error( - request, - _( + if not error_message: + message = _( + "One of the configured service did not provide a compliant response. " + "The cause of this exception was: {cause}" + ).format(cause=exc.__cause__) + else: + message = _( "Failed to retrieve available zaaktypen " "(got {http_status} - {detail}). " "The cause of this exception was: {cause}" @@ -62,6 +66,9 @@ def get_zaaktype_field(db_field: Field, request: HttpRequest, **kwargs): detail=error_message["detail"], cause=exc.__cause__, ), + messages.error( + request, + message, ) choices = [] except HTTPError as exc: From 20f286e7de74951a2ff8715b24878580a0121ccd Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:01:59 +0100 Subject: [PATCH 2/3] Fix issue when iterating over zaaktypen responses --- zgw_consumers/admin_fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zgw_consumers/admin_fields.py b/zgw_consumers/admin_fields.py index bcef383..5c7314d 100644 --- a/zgw_consumers/admin_fields.py +++ b/zgw_consumers/admin_fields.py @@ -35,11 +35,11 @@ def get_zaaktypen() -> Dict[Service, List[Dict[str, Any]]]: while response["next"]: next_url = urlparse(response["next"]) query = parse_qs(next_url.query) - new_page = int(query["page"][0]) + 1 + new_page = int(query["page"][0]) query["page"] = [new_page] response = client.list( "zaaktype", - query_params=query, + params=query, ) zaaktypen_per_service[service] += response["results"] From 40037b4bdd8ad7db26dabea4cb523e9932612f86 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:08:05 +0100 Subject: [PATCH 3/3] Fix format --- zgw_consumers/admin_fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zgw_consumers/admin_fields.py b/zgw_consumers/admin_fields.py index 5c7314d..41b1322 100644 --- a/zgw_consumers/admin_fields.py +++ b/zgw_consumers/admin_fields.py @@ -65,7 +65,7 @@ def get_zaaktype_field(db_field: Field, request: HttpRequest, **kwargs): http_status=error_message["status"], detail=error_message["detail"], cause=exc.__cause__, - ), + ) messages.error( request, message,