Skip to content

Commit bc50c85

Browse files
committed
fix: ping issue. reponse has changed
1 parent b1bbcfe commit bc50c85

File tree

1 file changed

+18
-7
lines changed
  • eventsourcingdb_client_python/handlers

1 file changed

+18
-7
lines changed

eventsourcingdb_client_python/handlers/ping.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
OK_RESPONSE = "OK"
88
STATUS_OK = "ok"
99

10+
1011
async def ping(client: AbstractBaseClient) -> None:
11-
response = await client.http_client.get('/api/v1/ping')
12-
response_body = bytes.decode(await response.body.read(), encoding='utf-8')
12+
response = await client.http_client.get("/api/v1/ping")
13+
response_body = bytes.decode(await response.body.read(), encoding="utf-8")
1314

1415
if response.status_code != HTTPStatus.OK:
15-
raise ServerError(f'Received unexpected response: {response_body}')
16+
raise ServerError(f"Received unexpected response: {response_body}")
1617

1718
# Check old format (plain "OK")
1819
if response_body == OK_RESPONSE:
@@ -21,9 +22,19 @@ async def ping(client: AbstractBaseClient) -> None:
2122
try:
2223
response_json = json.loads(response_body)
2324
except json.JSONDecodeError:
24-
pass
25-
else:
26-
if isinstance(response_json, dict) and response_json.get('status') == STATUS_OK:
25+
raise ServerError(f"Received unexpected response: {response_body}")
26+
27+
# Check if it's a JSON with status field
28+
if isinstance(response_json, dict) and response_json.get("status") == STATUS_OK:
29+
return
30+
31+
# Check if it's a CloudEvent format (has specversion, type fields)
32+
if (
33+
isinstance(response_json, dict)
34+
and "specversion" in response_json
35+
and "type" in response_json
36+
):
37+
if response_json.get("type") == "io.eventsourcingdb.ping-received":
2738
return
2839

29-
raise ServerError(f'Received unexpected response: {response_body}')
40+
raise ServerError(f"Received unexpected response: {response_body}")

0 commit comments

Comments
 (0)