diff --git a/app/enquiries/common/datahub_utils.py b/app/enquiries/common/datahub_utils.py index c69697eb..3f49a8f8 100644 --- a/app/enquiries/common/datahub_utils.py +++ b/app/enquiries/common/datahub_utils.py @@ -76,11 +76,11 @@ def dh_request( response = requests.post(url, headers=headers, json=payload, timeout=timeout) return response except Exception as e: - logger.error( + logger.exception( f"Error while requesting {url}: {e}" f"; request timeout set to {timeout} secs" ) - raise e + raise @cache_memoize(60 * 60) @@ -112,10 +112,7 @@ def fetch_metadata(name): response.raise_for_status() return response.json() except Exception as e: - logger.error( - f"Error fetching metadata for {name} from {url}: {e}" - f"; response body: {response.json()}" - ) + logger.exception(f"Error fetching metadata for {name} from {url}: {e}") raise diff --git a/app/enquiries/tests/test_dh_integration.py b/app/enquiries/tests/test_dh_integration.py index 7a512cfe..fe330cd8 100644 --- a/app/enquiries/tests/test_dh_integration.py +++ b/app/enquiries/tests/test_dh_integration.py @@ -143,10 +143,7 @@ def test_fetch_metadata_raises_error(self): f"Error fetching metadata for {metadata_name} from {url}" in message for message in log.output ) - assert any( - f"; response body: {response_json}" - in message for message in log.output - ) + assert any("Traceback" in message for message in log.output) def test_dh_request_raises_error(self): url = settings.DATA_HUB_COMPANY_SEARCH_URL @@ -166,6 +163,7 @@ def test_dh_request_raises_error(self): f"; request timeout set to {timeout} secs" in message for message in log.output ) + assert any("Traceback" in message for message in log.output) @mock.patch("requests.post") def test_dh_request_timeout(self, mock_post):