Skip to content

Commit

Permalink
Merge pull request #77 from maykinmedia/fix-error-handling
Browse files Browse the repository at this point in the history
Fix handling of zaaktypen responses
  • Loading branch information
sergei-maertens authored Dec 11, 2023
2 parents fa8b9d5 + 40037b4 commit 7de0c1e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions zgw_consumers/admin_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -51,17 +51,24 @@ 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}"
).format(
http_status=error_message["status"],
detail=error_message["detail"],
cause=exc.__cause__,
),
)
messages.error(
request,
message,
)
choices = []
except HTTPError as exc:
Expand Down

0 comments on commit 7de0c1e

Please sign in to comment.