From 9fefdf81aa8bbc78b5d9cf847f917975ba2d9dcf Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Fri, 3 Jul 2026 14:27:14 +0000 Subject: [PATCH] =?UTF-8?q?Abri=20log=5Fjob=20raises=20a=20retriable=20tra?= =?UTF-8?q?nsport=20error=20on=20an=20HTTP=20error=20status=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- infrastructure/abri/errors.py | 10 ++++++++++ tests/infrastructure/abri/test_abri_client.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 infrastructure/abri/errors.py diff --git a/infrastructure/abri/errors.py b/infrastructure/abri/errors.py new file mode 100644 index 000000000..39499293a --- /dev/null +++ b/infrastructure/abri/errors.py @@ -0,0 +1,10 @@ +class AbriTransportError(Exception): + """A transport-level relay failure; the request may be retried.""" + + +class AbriResponseParseError(AbriTransportError): + """An unparseable or unexpectedly-shaped relay response. + + Transport-class (retriable): the job may or may not have been logged, + so the outcome must never be treated as success or rejection. + """ diff --git a/tests/infrastructure/abri/test_abri_client.py b/tests/infrastructure/abri/test_abri_client.py index aaaeb7d38..d67624153 100644 --- a/tests/infrastructure/abri/test_abri_client.py +++ b/tests/infrastructure/abri/test_abri_client.py @@ -4,6 +4,7 @@ from pathlib import Path from unittest.mock import MagicMock, patch import pytest +import requests from domain.abri.models import ( AbriRequestRejected, @@ -13,6 +14,7 @@ from domain.abri.models import ( ) from infrastructure.abri.abri_client import AbriClient from infrastructure.abri.config import AbriConfig +from infrastructure.abri.errors import AbriTransportError FIXTURE_DIR = Path(__file__).parents[2] / "abri" ENDPOINT_URL = "https://relay.example.test/api/DomnaRelay?code=test-function-key" @@ -128,3 +130,20 @@ def test_log_job_returns_rejection_with_openhousing_error_code_and_message_verba "street name '', house number '0', house name '', post code ''" ), ) + + +# --- log_job: transport failures --- + + +def test_log_job_raises_transport_error_on_http_error_status( + client: AbriClient, mock_session: MagicMock +) -> None: + # Arrange + mock_session.post.return_value.content = b"Server Error" + mock_session.post.return_value.raise_for_status.side_effect = requests.HTTPError( + "500 Server Error" + ) + + # Act / Assert + with pytest.raises(AbriTransportError): + client.log_job(_spec_example_request())