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

Log traceback when exception is raised #999

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
response = requests.post(url, headers=headers, json=payload, timeout=timeout)
return response
except Exception as e:
logger.error(
logger.exception(

Check warning on line 79 in app/enquiries/common/datahub_utils.py

View check run for this annotation

Codecov / codecov/patch

app/enquiries/common/datahub_utils.py#L79

Added line #L79 was not covered by tests
f"Error while requesting {url}: {e}"
f"; request timeout set to {timeout} secs"
)
raise e
raise

Check warning on line 83 in app/enquiries/common/datahub_utils.py

View check run for this annotation

Codecov / codecov/patch

app/enquiries/common/datahub_utils.py#L83

Added line #L83 was not covered by tests


@cache_memoize(60 * 60)
Expand Down Expand Up @@ -112,10 +112,7 @@
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}")

Check warning on line 115 in app/enquiries/common/datahub_utils.py

View check run for this annotation

Codecov / codecov/patch

app/enquiries/common/datahub_utils.py#L115

Added line #L115 was not covered by tests
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