Skip to content

Commit 9cbefae

Browse files
committed
FIX: Fix client display of backend error messages
1 parent dd5b0d4 commit 9cbefae

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
### 0.19.0 - TBD
4+
5+
#### Enhancements
6+
- Added the `Publisher`, `Venue`, and `Dataset` enums.
7+
- Replace null prices with `NaN` when `pretty_px=True` in `DBNStore.to_df()`
8+
9+
#### Bug fixes
10+
- Fixed issue where exception messages were displaying JSON encoded data
11+
312
## 0.18.1 - 2023-08-16
413

514
#### Bug fixes

databento/common/error.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,23 @@ def __init__(
3737
self.http_status = http_status
3838
self.http_body = http_body
3939
self.json_body = json_body
40-
self.message = message
40+
41+
try:
42+
json_message = self.json_body["detail"]["message"]
43+
json_case = self.json_body["detail"]["case"]
44+
json_docs = self.json_body["detail"]["docs"]
45+
except (TypeError, KeyError):
46+
self.message = message
47+
else:
48+
composed_message = [
49+
json_case,
50+
json_message,
51+
]
52+
if json_docs:
53+
composed_message.append(f"documentation: {json_docs}")
54+
55+
self.message = "\n".join(composed_message)
56+
4157
self.headers = headers or {}
4258
self.request_id = self.headers.get("request-id", None)
4359

tests/test_historical_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def test_check_http_status_async(
6060
response = MagicMock(
6161
spec=aiohttp.ClientResponse,
6262
status=status_code,
63-
json=AsyncMock(return_value=MagicMock()),
63+
json=AsyncMock(return_value={}),
6464
)
6565
with pytest.raises(expected_exception) as exc:
6666
await check_http_error_async(response)

tests/test_historical_timeseries.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ def test_get_range_error_no_file_write(
6262
) -> None:
6363
# Arrange
6464
mocked_response = MagicMock()
65-
mocked_response.__enter__.return_value = MagicMock(status_code=500)
65+
mocked_response.__enter__.return_value = MagicMock(
66+
status_code=500,
67+
json=MagicMock(
68+
return_value={},
69+
),
70+
)
6671
monkeypatch.setattr(requests, "post", MagicMock(return_value=mocked_response))
6772

6873
output_file = tmp_path / "output.dbn"

0 commit comments

Comments
 (0)