File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
eventsourcingdb_client_python/handlers Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 11from http import HTTPStatus
22import json
3-
43from ..abstract_base_client import AbstractBaseClient
54from ..errors .server_error import ServerError
65
6+ # Define constants for response values
7+ OK_RESPONSE = "OK"
8+ STATUS_OK = "ok"
9+
710async def ping (client : AbstractBaseClient ) -> None :
811 response = await client .http_client .get ('/api/v1/ping' )
912 response_body = bytes .decode (await response .body .read (), encoding = 'utf-8' )
1013
14+ if response .status_code != HTTPStatus .OK :
15+ raise ServerError (f'Received unexpected response: { response_body } ' )
16+
17+ # Check old format (plain "OK")
18+ if response_body == OK_RESPONSE :
19+ return
20+
21+ # Check new format (JSON {"status":"ok"})
1122 try :
1223 response_json = json .loads (response_body )
24+ if isinstance (response_json , dict ) and response_json .get ('status' ) == STATUS_OK :
25+ return
1326 except json .JSONDecodeError :
1427 pass
15- else :
16- if isinstance (response_json , dict ) and response_json .get ('status' ) == 'ok' :
17- return None
18- raise ServerError (f'Received unexpected response: { response_body } ' )
28+
29+ raise ServerError (f'Received unexpected response: { response_body } ' )
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ async def ping_app() -> RetryResult[None]:
4848 async with session :
4949 try :
5050 response = await session .get (
51- f'http://localhost:{ local_http_server .port } /__python_test__/api/v1/ping' , timeout = 1
51+ f'http://localhost:{ local_http_server .port } /__python_test__/api/v1/ping' , timeout = aiohttp . ClientTimeout ( total = 1 )
5252 )
5353 except aiohttp .ClientError as error :
5454 return Retry (cause = error )
You can’t perform that action at this time.
0 commit comments