diff --git a/marklogic/transactions.py b/marklogic/transactions.py index 02ed1a8..50c7d95 100644 --- a/marklogic/transactions.py +++ b/marklogic/transactions.py @@ -1,5 +1,6 @@ import logging from requests import Response, Session +from requests.exceptions import HTTPError logger = logging.getLogger(__name__) @@ -71,9 +72,10 @@ def __exit__(self, *args): if len(args) > 1 and isinstance(args[1], Exception) else self.commit() ) - assert ( - 204 == response.status_code - ), f"Could not end transaction; cause: {response.text}" + # raise_for_status() is not used here as it results in an error without any + # context of what went wrong. + if response.status_code != 204: + raise HTTPError(f"Could not end transaction; cause: {response.text}") class TransactionManager: diff --git a/tests/test_transactions.py b/tests/test_transactions.py index a2ca3e7..1228a10 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -2,6 +2,7 @@ import time from marklogic import Client from marklogic.documents import Document +from requests.exceptions import HTTPError PERMS = {"python-tester": ["read", "update"]} @@ -65,7 +66,7 @@ def test_time_limit(client: Client): doc1 = Document("/t1.json", {}, permissions=PERMS) client.documents.write(doc1, tx=tx) - except AssertionError as error: + except HTTPError as error: assert error.args[0].startswith("Could not end transaction") assert "No transaction with identifier" in error.args[0] assert "XDMP-NOTXN" in error.args[0]