Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #999 from uktrade/hotfix/CPS-600-fix-exception-log…
Browse files Browse the repository at this point in the history
…ging-during-requests-to-data-hub

Log traceback when exception is raised
  • Loading branch information
oliverjwroberts authored Jul 30, 2024
2 parents 0d95a15 + 9c5e372 commit b4757ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
9 changes: 3 additions & 6 deletions app/enquiries/common/datahub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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


Expand Down
6 changes: 2 additions & 4 deletions app/enquiries/tests/test_dh_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit b4757ef

Please sign in to comment.