Raise MultiselectCommunicatorError
:
when failed to write to communicator
This commit is contained in:
parent
b9d1875027
commit
c6294ad19b
|
@ -59,12 +59,18 @@ class Multiselect(IMultiselectMuxer):
|
|||
protocol = TProtocol(command)
|
||||
if protocol in self.handlers:
|
||||
# Tell counterparty we have decided on a protocol
|
||||
await communicator.write(protocol)
|
||||
try:
|
||||
await communicator.write(protocol)
|
||||
except MultiselectCommunicatorError as error:
|
||||
raise MultiselectError(error)
|
||||
|
||||
# Return the decided on protocol
|
||||
return protocol, self.handlers[protocol]
|
||||
# Tell counterparty this protocol was not found
|
||||
await communicator.write(PROTOCOL_NOT_FOUND_MSG)
|
||||
try:
|
||||
await communicator.write(PROTOCOL_NOT_FOUND_MSG)
|
||||
except MultiselectCommunicatorError as error:
|
||||
raise MultiselectError(error)
|
||||
|
||||
async def handshake(self, communicator: IMultiselectCommunicator) -> None:
|
||||
"""
|
||||
|
@ -76,7 +82,10 @@ class Multiselect(IMultiselectMuxer):
|
|||
# TODO: Use format used by go repo for messages
|
||||
|
||||
# Send our MULTISELECT_PROTOCOL_ID to other party
|
||||
await communicator.write(MULTISELECT_PROTOCOL_ID)
|
||||
try:
|
||||
await communicator.write(MULTISELECT_PROTOCOL_ID)
|
||||
except MultiselectCommunicatorError as error:
|
||||
raise MultiselectError(error)
|
||||
|
||||
# Read in the protocol ID from other party
|
||||
try:
|
||||
|
|
|
@ -27,7 +27,10 @@ class MultiselectClient(IMultiselectClient):
|
|||
# TODO: Use format used by go repo for messages
|
||||
|
||||
# Send our MULTISELECT_PROTOCOL_ID to counterparty
|
||||
await communicator.write(MULTISELECT_PROTOCOL_ID)
|
||||
try:
|
||||
await communicator.write(MULTISELECT_PROTOCOL_ID)
|
||||
except MultiselectCommunicatorError as error:
|
||||
raise MultiselectClientError(error)
|
||||
|
||||
# Read in the protocol ID from other party
|
||||
try:
|
||||
|
@ -79,7 +82,10 @@ class MultiselectClient(IMultiselectClient):
|
|||
"""
|
||||
|
||||
# Tell counterparty we want to use protocol
|
||||
await communicator.write(protocol)
|
||||
try:
|
||||
await communicator.write(protocol)
|
||||
except MultiselectCommunicatorError as error:
|
||||
raise MultiselectClientError(error)
|
||||
|
||||
# Get what counterparty says in response
|
||||
try:
|
||||
|
|
|
@ -15,7 +15,12 @@ class MultiselectCommunicator(IMultiselectCommunicator):
|
|||
|
||||
async def write(self, msg_str: str) -> None:
|
||||
msg_bytes = encode_delim(msg_str.encode())
|
||||
await self.read_writer.write(msg_bytes)
|
||||
try:
|
||||
await self.read_writer.write(msg_bytes)
|
||||
except IOException:
|
||||
raise MultiselectCommunicatorError(
|
||||
"fail to write to multiselect communicator"
|
||||
)
|
||||
|
||||
async def read(self) -> str:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue
Block a user