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

[#3021] Catch API errors when fetching related questions #1608

Merged
merged 1 commit into from
Feb 6, 2025
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
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
Loading