Handling Errors¶
handling_errors.py¶
1from zcached import ZCached, Result, Errors
2
3client = ZCached(host="localhost", port=1234)
4client.run()
5
6
7def handle_error(error_message: str) -> None:
8 if error_message == Errors.ConnectionReestablished:
9 return # The connection was dropped, but managed to restore it.
10 if error_message == Errors.NoAvailableConnections:
11 connections: int = client.connection_pool.reconnect()
12 if connections >= 1: # It was able to connect the broken connections.
13 return
14 raise RuntimeError(error_message)
15
16
17result: Result[str] = client.get("key123")
18if result.error:
19 handle_error(error_message=result.error)