diff --git a/src/open_inwoner/accounts/signals.py b/src/open_inwoner/accounts/signals.py index a7fce05d56..f1d869fb1e 100644 --- a/src/open_inwoner/accounts/signals.py +++ b/src/open_inwoner/accounts/signals.py @@ -8,6 +8,7 @@ from open_inwoner.haalcentraal.models import HaalCentraalConfig from open_inwoner.haalcentraal.utils import update_brp_data_in_db +from open_inwoner.openklant.exceptions import KlantenServiceError from open_inwoner.openklant.models import OpenKlant2Config from open_inwoner.openklant.services import OpenKlant2Service, eSuiteKlantenService from open_inwoner.utils.logentry import user_action @@ -42,7 +43,7 @@ def update_user_from_klant_on_login(sender, user, request, *args, **kwargs): if use_ok2 and (openklant2_config := OpenKlant2Config.from_django_settings()): try: service = OpenKlant2Service(config=openklant2_config) - except RuntimeError: + except KlantenServiceError: logger.error("OpenKlant2 service failed to build") return @@ -58,7 +59,7 @@ def update_user_from_klant_on_login(sender, user, request, *args, **kwargs): # eSuite try: service = eSuiteKlantenService() - except RuntimeError: + except KlantenServiceError: logger.error("eSuiteKlantenService failed to build") return diff --git a/src/open_inwoner/accounts/views/contactmoments.py b/src/open_inwoner/accounts/views/contactmoments.py index 819a7ea85c..bc12e3ac9a 100644 --- a/src/open_inwoner/accounts/views/contactmoments.py +++ b/src/open_inwoner/accounts/views/contactmoments.py @@ -2,6 +2,7 @@ from datetime import datetime from typing import TypedDict +from django.contrib import messages from django.contrib.auth.mixins import AccessMixin from django.http import Http404, HttpResponseRedirect from django.shortcuts import redirect @@ -12,6 +13,7 @@ from django.views.generic import TemplateView from glom import glom +from requests.exceptions import RequestException from view_breadcrumbs import BaseBreadcrumbMixin from open_inwoner.openklant.api_models import KlantContactMoment @@ -35,6 +37,7 @@ ) from open_inwoner.openzaak.clients import MultiZgwClientProxy from open_inwoner.openzaak.models import ZGWApiGroupConfig +from open_inwoner.utils.api import ClientError from open_inwoner.utils.mixins import PaginationMixin from open_inwoner.utils.views import CommonPageMixin @@ -175,9 +178,20 @@ def get_anchors(self) -> list: def get_context_data(self, **kwargs): ctx = super().get_context_data(**kwargs) - kcms = fetch_klantcontactmomenten( - **get_fetch_parameters(self.request, use_vestigingsnummer=True) - ) + try: + kcms = fetch_klantcontactmomenten( + **get_fetch_parameters(self.request, use_vestigingsnummer=True) + ) + # TODO: replace with custom exception when openklant refactor is done + except (RequestException, ClientError): + kcms = [] + messages.add_message( + self.request, + messages.ERROR, + _( + "Het was niet mogelijk om uw vragen op te halen, probeer het later nog eens" + ), + ) klant_config = OpenKlantConfig.get_solo() if exclude_range := klant_config.exclude_contactmoment_kanalen: diff --git a/src/open_inwoner/accounts/views/mixins.py b/src/open_inwoner/accounts/views/mixins.py index 7d26dac4a3..56095c83b0 100644 --- a/src/open_inwoner/accounts/views/mixins.py +++ b/src/open_inwoner/accounts/views/mixins.py @@ -1,5 +1,6 @@ import logging +from open_inwoner.openklant.exceptions import KlantenServiceError from open_inwoner.openklant.models import OpenKlantConfig from open_inwoner.openklant.services import eSuiteKlantenService @@ -13,7 +14,7 @@ def patch_klant(self, update_data: dict): try: service = eSuiteKlantenService(config=OpenKlantConfig.get_solo()) - except RuntimeError: + except KlantenServiceError: logger.error("Error building KlantenService") return diff --git a/src/open_inwoner/accounts/views/signals.py b/src/open_inwoner/accounts/views/signals.py index 04177e0f05..98e103b438 100644 --- a/src/open_inwoner/accounts/views/signals.py +++ b/src/open_inwoner/accounts/views/signals.py @@ -5,6 +5,7 @@ from django.dispatch import receiver from open_inwoner.accounts.models import User +from open_inwoner.openklant.exceptions import KlantenServiceError from open_inwoner.openklant.models import OpenKlant2Config from open_inwoner.openklant.services import OpenKlant2Service, eSuiteKlantenService @@ -28,7 +29,7 @@ def get_or_create_klant_for_new_user( if use_ok2 and (openklant2_config := OpenKlant2Config.from_django_settings()): try: service = OpenKlant2Service(config=openklant2_config) - except RuntimeError: + except KlantenServiceError: logger.error("OpenKlant2 service failed to build") return @@ -53,7 +54,7 @@ def get_or_create_klant_for_new_user( # eSuite try: service = eSuiteKlantenService() - except RuntimeError: + except KlantenServiceError: logger.error("eSuiteKlantenService failed to build") return diff --git a/src/open_inwoner/cms/cases/views/cases.py b/src/open_inwoner/cms/cases/views/cases.py index d7f806bdab..3b46097991 100644 --- a/src/open_inwoner/cms/cases/views/cases.py +++ b/src/open_inwoner/cms/cases/views/cases.py @@ -1,6 +1,7 @@ import logging from typing import Sequence +from django.contrib import messages from django.urls import reverse from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ @@ -15,6 +16,7 @@ from open_inwoner.utils.mixins import PaginationMixin from open_inwoner.utils.views import CommonPageMixin +from .exceptions import ZakenServiceError from .mixins import CaseAccessMixin, CaseLogMixin, OuterCaseAccessMixin from .services import CaseFilterFormOption, CaseListService @@ -70,8 +72,19 @@ def get_context_data(self, **kwargs): context["filter_form_enabled"] = config.zaken_filter_enabled # update ctx with open submissions and cases (possibly fitered) - open_submissions: Sequence[UniformCase] = case_service.get_submissions() - preprocessed_cases: Sequence[UniformCase] = case_service.get_cases() + open_submissions = [] + preprocessed_cases = [] + try: + open_submissions: Sequence[UniformCase] = case_service.get_submissions() + preprocessed_cases: Sequence[UniformCase] = case_service.get_cases() + except ZakenServiceError: + messages.add_message( + self.request, + messages.ERROR, + _( + "Het was niet mogelijk om uw anvragen op te halen, probeer het later nog eens" + ), + ) if config.zaken_filter_enabled: case_status_frequencies = case_service.get_case_status_frequencies() diff --git a/src/open_inwoner/cms/cases/views/exceptions.py b/src/open_inwoner/cms/cases/views/exceptions.py new file mode 100644 index 0000000000..2e35032908 --- /dev/null +++ b/src/open_inwoner/cms/cases/views/exceptions.py @@ -0,0 +1,2 @@ +class ZakenServiceError(Exception): + pass diff --git a/src/open_inwoner/cms/cases/views/services.py b/src/open_inwoner/cms/cases/views/services.py index d9ae67e08c..7e1b222bfa 100644 --- a/src/open_inwoner/cms/cases/views/services.py +++ b/src/open_inwoner/cms/cases/views/services.py @@ -19,6 +19,8 @@ ) from open_inwoner.openzaak.utils import get_user_fetch_parameters, is_zaak_visible +from .exceptions import ZakenServiceError + logger = logging.getLogger(__name__) @@ -131,6 +133,7 @@ def get_submissions(self) -> list[SubmissionWithApiGroup]: ) except BaseException: logger.exception("Error fetching and pre-processing cases") + raise ZakenServiceError # Sort submissions by date modified subs_with_api_group.sort( @@ -184,6 +187,7 @@ def get_cases(self) -> list[ZaakWithApiGroup]: "Error while fetching and pre-processing cases for API group %s", group_for_task, ) + raise # Ensure stable sorting for pagination and testing purposes cases_with_api_group.sort(key=lambda c: all_api_groups.index(c.api_group)) diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index 9efa197b90..0cc322f27a 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -26,6 +26,7 @@ from zgw_consumers.api_models.constants import RolOmschrijving from open_inwoner.mail.service import send_contact_confirmation_mail +from open_inwoner.openklant.exceptions import KlantenServiceError from open_inwoner.openklant.models import OpenKlantConfig from open_inwoner.openklant.services import eSuiteKlantenService, eSuiteVragenService from open_inwoner.openklant.wrap import ( @@ -165,14 +166,22 @@ def get_context_data(self, **kwargs): # questions/E-suite contactmomenten try: service = eSuiteVragenService(config=openklant_config) - except RuntimeError: - logger.error("Failed to build eSuiteVragenService") - objectcontactmomenten = [] - else: objectcontactmomenten = service.retrieve_objectcontactmomenten_for_zaak( self.case ) - + except KlantenServiceError: + logger.error( + "There was a problem fetching objectcontactmomenten with eSuiteVragenService for %s" + % self.case + ) + objectcontactmomenten = [] + messages.add_message( + self.request, + messages.ERROR, + _( + "Het was niet mogelijk om uw vragen op te halen, probeer het later nog eens" + ), + ) questions = [] for ocm in objectcontactmomenten: question = getattr(ocm, "contactmoment", None) diff --git a/src/open_inwoner/openklant/clients.py b/src/open_inwoner/openklant/clients.py index 96b6459ada..24d4e2a7de 100644 --- a/src/open_inwoner/openklant/clients.py +++ b/src/open_inwoner/openklant/clients.py @@ -114,7 +114,7 @@ def retrieve_klanten_for_bsn(self, user_bsn: str) -> list[Klant]: all_data = list(pagination_helper(self, data)) except (RequestException, ClientError) as e: logger.exception("exception while making request", exc_info=e) - return [] + raise klanten = factory(Klant, all_data) @@ -139,7 +139,7 @@ def retrieve_klanten_for_kvk_or_rsin( all_data = list(pagination_helper(self, data)) except (RequestException, ClientError) as e: logger.exception("exception while making request", exc_info=e) - return [] + raise klanten = factory(Klant, all_data) @@ -243,7 +243,7 @@ def retrieve_objectcontactmomenten_for_zaak( all_data = list(pagination_helper(self, data)) except (RequestException, ClientError) as exc: logger.exception("exception while making request", exc_info=exc) - return [] + raise object_contact_momenten = factory(ObjectContactMoment, all_data) diff --git a/src/open_inwoner/openklant/exceptions.py b/src/open_inwoner/openklant/exceptions.py new file mode 100644 index 0000000000..d2dea0500f --- /dev/null +++ b/src/open_inwoner/openklant/exceptions.py @@ -0,0 +1,2 @@ +class KlantenServiceError(Exception): + pass diff --git a/src/open_inwoner/openklant/services.py b/src/open_inwoner/openklant/services.py index 0c08753c40..8f4c979dc0 100644 --- a/src/open_inwoner/openklant/services.py +++ b/src/open_inwoner/openklant/services.py @@ -27,6 +27,7 @@ KlantCreateData, ObjectContactMoment, ) +from open_inwoner.openklant.exceptions import KlantenServiceError from open_inwoner.openklant.models import OpenKlant2Config, OpenKlantConfig from open_inwoner.openzaak.api_models import Zaak from open_inwoner.utils.api import ClientError, get_json_response @@ -97,17 +98,19 @@ class eSuiteKlantenService(KlantenService): def __init__(self, config: OpenKlantConfig | None = None): self.config = config or OpenKlantConfig.get_solo() if not self.config: - raise RuntimeError("eSuiteKlantenService instance needs a configuration") + raise KlantenServiceError( + "eSuiteKlantenService instance needs a configuration" + ) self.service_config = self.config.klanten_service if not self.service_config: - raise RuntimeError( + raise KlantenServiceError( "eSuiteKlantenService instance needs a servivce configuration" ) self.client = build_zgw_client(service=self.service_config) if not self.client: - raise RuntimeError("eSuiteKlantenService instance needs a client") + raise KlantenServiceError("eSuiteKlantenService instance needs a client") def get_or_create_klant( self, fetch_params: FetchParameters, user: User @@ -312,17 +315,19 @@ class eSuiteVragenService(KlantenService): def __init__(self, config: OpenKlantConfig | None = None): self.config = config or OpenKlantConfig.get_solo() if not self.config: - raise RuntimeError("eSuiteVragenService instance needs a configuration") + raise KlantenServiceError( + "eSuiteVragenService instance needs a configuration" + ) self.service_config = self.config.contactmomenten_service if not self.service_config: - raise RuntimeError( + raise KlantenServiceError( "eSuiteVragenService instance needs a servivce configuration" ) self.client = build_zgw_client(service=self.service_config) if not self.client: - raise RuntimeError("eSuiteVragenService instance needs a client") + raise KlantenServiceError("eSuiteVragenService instance needs a client") # # contactmomenten @@ -430,7 +435,7 @@ def retrieve_objectcontactmomenten_for_zaak( all_data = list(pagination_helper(self, data)) except (RequestException, ClientError) as exc: logger.exception("exception while making request", exc_info=exc) - return [] + raise KlantenServiceError object_contact_momenten = factory(ObjectContactMoment, all_data) @@ -550,7 +555,9 @@ class OpenKlant2Service(KlantenService): def __init__(self, config: OpenKlant2Config | None = None): self.config = config or OpenKlant2Config.from_django_settings() if not self.config: - raise RuntimeError("OpenKlant2Service instance needs a configuration") + raise KlantenServiceError( + "OpenKlant2Service instance needs a configuration" + ) self.client = OpenKlant2Client( base_url=self.config.api_url, @@ -559,7 +566,7 @@ def __init__(self, config: OpenKlant2Config | None = None): }, ) if not self.client: - raise RuntimeError("OpenKlant2Service instance needs a client") + raise KlantenServiceError("OpenKlant2Service instance needs a client") if mijn_vragen_actor := getattr(config, "mijn_vragen_actor", None): self.mijn_vragen_actor = ( diff --git a/src/open_inwoner/openzaak/clients.py b/src/open_inwoner/openzaak/clients.py index 34cf75626f..7d34397b60 100644 --- a/src/open_inwoner/openzaak/clients.py +++ b/src/open_inwoner/openzaak/clients.py @@ -130,7 +130,7 @@ def fetch_cases_by_bsn( headers=CRS_HEADERS, ) ) - except (RequestException, ClientError) as e: + except (RequestException, ClientError, Exception) as e: logger.exception("exception while making request", exc_info=e) return [] diff --git a/src/open_inwoner/templates/pages/cases/list_inner.html b/src/open_inwoner/templates/pages/cases/list_inner.html index 80f2fb4c93..67b5aea6b4 100644 --- a/src/open_inwoner/templates/pages/cases/list_inner.html +++ b/src/open_inwoner/templates/pages/cases/list_inner.html @@ -1,4 +1,10 @@ -{% load link_tags button_tags i18n grid_tags icon_tags list_tags pagination_tags utils %} +{% load link_tags button_tags i18n grid_tags icon_tags list_tags notification_tags pagination_tags utils %} + +{% block notifications %} +
{{ title_text }}