77OK_RESPONSE = "OK"
88STATUS_OK = "ok"
99
10+ # CloudEvent field names
11+ SPECVERSION_FIELD = "specversion"
12+ TYPE_FIELD = "type"
13+ PING_RECEIVED_TYPE = "io.eventsourcingdb.ping-received"
14+
1015
1116async def ping (client : AbstractBaseClient ) -> None :
1217 response = await client .http_client .get ("/api/v1/ping" )
@@ -21,8 +26,8 @@ async def ping(client: AbstractBaseClient) -> None:
2126
2227 try :
2328 response_json = json .loads (response_body )
24- except json .JSONDecodeError :
25- raise ServerError (f"Received unexpected response: { response_body } " )
29+ except json .JSONDecodeError as exc :
30+ raise ServerError (f"Received unexpected response: { response_body } " ) from exc
2631
2732 # Check if it's a JSON with status field
2833 if isinstance (response_json , dict ) and response_json .get ("status" ) == STATUS_OK :
@@ -31,10 +36,10 @@ async def ping(client: AbstractBaseClient) -> None:
3136 # Check if it's a CloudEvent format (has specversion, type fields)
3237 if (
3338 isinstance (response_json , dict )
34- and "specversion" in response_json
35- and "type" in response_json
39+ and SPECVERSION_FIELD in response_json
40+ and TYPE_FIELD in response_json
3641 ):
37- if response_json .get ("type" ) == "io.eventsourcingdb.ping-received" :
42+ if response_json .get (TYPE_FIELD ) == PING_RECEIVED_TYPE :
3843 return
3944
4045 raise ServerError (f"Received unexpected response: { response_body } " )
0 commit comments