Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified error handling codestyle in ZGW fetch-functions #562

Merged
merged 2 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/open_inwoner/haalcentraal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ def fetch_brp_data(instance, brp_version):
headers={"Accept": "application/hal+json"}, verify=False
),
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return {}
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return {}

Expand All @@ -68,10 +65,7 @@ def fetch_brp_data(instance, brp_version):
verify=False,
),
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return {}
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return {}

Expand Down
55 changes: 11 additions & 44 deletions src/open_inwoner/openzaak/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ def fetch_cases(user_bsn: str, max_cases: Optional[int] = 100) -> List[Zaak]:
},
},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand All @@ -65,10 +62,7 @@ def fetch_single_case(case_uuid: str) -> Optional[Zaak]:

try:
response = client.retrieve("zaak", uuid=case_uuid)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand All @@ -88,10 +82,7 @@ def fetch_single_case_information_object(url: str) -> Optional[ZaakInformatieObj

try:
response = client.retrieve("zaakinformatieobject", url=url)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand All @@ -104,10 +95,7 @@ def fetch_case_by_url_no_cache(case_url: str) -> Optional[Zaak]:
client = build_client("zaak")
try:
response = client.retrieve("zaak", url=case_url)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand All @@ -130,10 +118,7 @@ def fetch_case_information_objects(case_url: str) -> List[ZaakInformatieObject]:
"params": {"zaak": case_url},
},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand All @@ -155,10 +140,7 @@ def fetch_status_history_no_cache(case_url: str) -> List[Status]:

try:
response = client.list("status", request_kwargs={"params": {"zaak": case_url}})
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand All @@ -176,10 +158,7 @@ def fetch_single_status(status_url: str) -> Optional[Status]:

try:
response = client.retrieve("status", url=status_url)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand Down Expand Up @@ -213,10 +192,7 @@ def fetch_case_roles(
"rol",
request_kwargs={"params": params},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand Down Expand Up @@ -270,10 +246,7 @@ def fetch_case_information_objects_for_case_and_info(
},
},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand All @@ -291,10 +264,7 @@ def fetch_single_result(result_url: str) -> Optional[Resultaat]:

try:
response = client.retrieve("result", url=result_url)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand All @@ -313,10 +283,7 @@ def connect_case_with_document(case_url: str, document_url: str) -> Optional[dic
response = client.create(
"zaakinformatieobject", {"zaak": case_url, "informatieobject": document_url}
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand Down
40 changes: 8 additions & 32 deletions src/open_inwoner/openzaak/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def fetch_status_types_no_cache(case_type_url: str) -> List[StatusType]:
"statustype",
request_kwargs={"params": {"zaaktype": case_type_url}},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand All @@ -56,10 +53,7 @@ def fetch_result_types_no_cache(case_type_url: str) -> List[ResultaatType]:
"resultaattype",
request_kwargs={"params": {"zaaktype": case_type_url}},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand All @@ -79,10 +73,7 @@ def fetch_single_status_type(status_type_url: str) -> Optional[StatusType]:

try:
response = client.retrieve("statustype", url=status_type_url)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand All @@ -104,10 +95,7 @@ def fetch_zaaktypes_no_cache() -> List[ZaakType]:

try:
response = get_paginated_results(client, "zaaktype")
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand Down Expand Up @@ -138,10 +126,7 @@ def fetch_case_types_by_identification_no_cache(
"zaaktype",
request_kwargs={"params": params},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand Down Expand Up @@ -174,10 +159,7 @@ def fetch_single_case_type(case_type_url: str) -> Optional[ZaakType]:

try:
response = client.retrieve("zaaktype", url=case_type_url)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand All @@ -200,10 +182,7 @@ def fetch_catalogs_no_cache() -> List[Catalogus]:
client,
"catalogus",
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand All @@ -228,10 +207,7 @@ def fetch_single_information_object_type(
response = client.retrieve(
"informatieobjecttype", url=information_object_type_url
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand Down
15 changes: 3 additions & 12 deletions src/open_inwoner/openzaak/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

from open_inwoner.openzaak.api_models import InformatieObject
from open_inwoner.openzaak.clients import build_client
from open_inwoner.openzaak.models import (
OpenZaakConfig,
ZaakTypeInformatieObjectTypeConfig,
)
from open_inwoner.openzaak.models import OpenZaakConfig

from .utils import cache as cache_result

Expand Down Expand Up @@ -50,10 +47,7 @@ def _fetch_single_information_object(
response = client.retrieve("enkelvoudiginformatieobject", url=url)
else:
response = client.retrieve("enkelvoudiginformatieobject", uuid=uuid)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand Down Expand Up @@ -125,10 +119,7 @@ def upload_document(

try:
response = client.create("enkelvoudiginformatieobject", document_body)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

Expand Down
5 changes: 1 addition & 4 deletions src/open_inwoner/openzaak/formapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ def fetch_open_submissions(bsn: str) -> List[OpenSubmission]:
"opensubmission",
request_kwargs={"params": {"bsn": bsn}},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return []

Expand Down