diff --git a/src/open_inwoner/ssd/client.py b/src/open_inwoner/ssd/client.py index 2988654588..b7a0bbc6c4 100644 --- a/src/open_inwoner/ssd/client.py +++ b/src/open_inwoner/ssd/client.py @@ -79,9 +79,9 @@ def templated_request(self, **kwargs) -> Response: headers=headers, **auth_kwargs, ) - except requests.exceptions.RequestException: - logger.exception("Requests exception") - raise + except requests.exceptions.RequestException as e: + logger.exception("Requests exception: %s", e) + return return response @@ -142,7 +142,7 @@ def get_reports( response = self.templated_request(bsn=bsn, dienstjaar=report_date) - if response.status_code != 200: + if not response or response.status_code != 200: return None jaaropgaven = get_jaaropgaven(response) @@ -198,7 +198,7 @@ def get_reports( response = self.templated_request(bsn=bsn, period=report_date) - if response.status_code != 200: + if not response or response.status_code != 200: return None uitkeringen = get_uitkeringen(response) diff --git a/src/open_inwoner/ssd/tests/test_client.py b/src/open_inwoner/ssd/tests/test_client.py index c65ff4208c..1e949c359f 100644 --- a/src/open_inwoner/ssd/tests/test_client.py +++ b/src/open_inwoner/ssd/tests/test_client.py @@ -6,6 +6,7 @@ import requests_mock from lxml import etree +from requests.exceptions import ConnectionError from ..client import JaaropgaveClient, UitkeringClient from .factories import ConcreteSSDClient, SSDConfigFactory @@ -125,6 +126,18 @@ def test_tsl_client_cert_and_private_key(self, mock_request_body, mock_request): ), ) + @patch("open_inwoner.ssd.client.requests.post", side_effect=ConnectionError) + def test_requests_exception(self, mock_request_body, mock_request_post): + ssd_client = ConcreteSSDClient() + ssd_client.config = SSDConfigFactory.build( + service__url="https://example.com/soap-service", + ) + + context = {"bsn": "dummy", "period": "dummy"} + response = ssd_client.templated_request(**context) + + self.assertIsNone(response) + class UitkeringClientTest(TestCase): @requests_mock.Mocker() diff --git a/src/open_inwoner/ssd/xml.py b/src/open_inwoner/ssd/xml.py index bb224029bd..fda4ffdc0a 100644 --- a/src/open_inwoner/ssd/xml.py +++ b/src/open_inwoner/ssd/xml.py @@ -4,7 +4,7 @@ import requests from lxml import etree # nosec -from lxml.etree import LxmlError # nosec +from lxml.etree import LxmlError, XMLSyntaxError # nosec from xsdata.exceptions import ParserError from xsdata.formats.dataclass.context import XmlContext from xsdata.formats.dataclass.parsers import XmlParser @@ -45,7 +45,7 @@ def _get_report_info( try: tree = etree.fromstring(response.content).getroottree() node = tree.find(info_response_node) - except LxmlError: + except (LxmlError, XMLSyntaxError): return None parser = XmlParser(context=XmlContext(), handler=LxmlEventHandler)