Skip to content

Commit

Permalink
[#3021] Catch API errors when fetching related questions
Browse files Browse the repository at this point in the history
  • Loading branch information
swrichards committed Feb 6, 2025
1 parent ba5599e commit f89e82b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
36 changes: 22 additions & 14 deletions src/open_inwoner/accounts/views/contactmoments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.views import View
from django.views.generic import TemplateView

from requests import RequestException
from view_breadcrumbs import BaseBreadcrumbMixin

from open_inwoner.accounts.models import User
Expand Down Expand Up @@ -146,20 +147,27 @@ def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)

questions = []
if ok2_service := self.get_service(service_type=KlantenServiceType.OPENKLANT2):
questions.extend(
ok2_service.list_questions(
self.get_fetch_params(ok2_service),
user=self.request.user,
)
)
if esuite_service := self.get_service(service_type=KlantenServiceType.ESUITE):
questions.extend(
esuite_service.list_questions(
fetch_params=self.get_fetch_params(esuite_service),
user=self.request.user,
)
)
for service_type in KlantenServiceType:
if service := self.get_service(service_type=service_type):
try:
service_questions = service.list_questions(
self.get_fetch_params(service),
user=self.request.user,
)
questions.extend(service_questions)
except RequestException:
# TODO: This can happen. Ideally, we would present the user with
# warning noting that not all questions might be visible.
logger.warning(
"Connection error for service %s",
service_type,
exc_info=True,
)
except BaseException:
logger.exception(
"Unable to fetch questions for service %s", service_type
)

questions.sort(key=lambda q: q["registered_date"], reverse=True)
ctx["questions"] = questions

Expand Down
37 changes: 21 additions & 16 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from django_htmx.http import HttpResponseClientRedirect
from mail_editor.helpers import find_template
from requests import RequestException
from view_breadcrumbs import BaseBreadcrumbMixin
from zgw_consumers.api_models.constants import RolOmschrijving

Expand Down Expand Up @@ -194,22 +195,26 @@ def get_context_data(self, **kwargs):
self.store_resulttype_mapping(self.case.zaaktype.identificatie)

questions = []
if ok2_service := self.get_service(
service_type=KlantenServiceType.OPENKLANT2
):
questions.extend(
ok2_service.list_questions_for_zaak(
self.case, user=self.request.user
)
)
if esuite_service := self.get_service(
service_type=KlantenServiceType.ESUITE
):
questions.extend(
esuite_service.list_questions_for_zaak(
self.case, user=self.request.user
)
)
for service_type in KlantenServiceType:
if service := self.get_service(service_type=service_type):
try:
service_questions = service.list_questions_for_zaak(
self.case, user=self.request.user
)
questions.extend(service_questions)
except RequestException:
# TODO: This can happen. Ideally, we would present the user with
# warning noting that not all questions might be visible.
logger.warning(
"Connection error for service %s",
service_type,
exc_info=True,
)
except BaseException:
logger.exception(
"Unable to fetch questions for service %s", service_type
)

questions.sort(key=lambda q: q["registered_date"], reverse=True)

statustypen = []
Expand Down

0 comments on commit f89e82b

Please sign in to comment.