From fe00d09a64b53264ae9af6405ef689e7ec4e2f0f Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 13 Dec 2023 11:15:15 +0200 Subject: [PATCH] Add the error if the producer could not connect to the server. --- notification_producer/producer_client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/notification_producer/producer_client.py b/notification_producer/producer_client.py index f06cc30..f0623c8 100644 --- a/notification_producer/producer_client.py +++ b/notification_producer/producer_client.py @@ -36,8 +36,12 @@ class ProducerClient: self.writer = None async def connect(self): - self.reader, self.writer = await asyncio.open_connection(self.__ip, self.__port) - self.console.print(f'[yellow b][INFO][/] Connected to the server ({self.__ip}:{self.__port}).') + try: + self.reader, self.writer = await asyncio.open_connection(self.__ip, self.__port) + self.console.print(f'[yellow b][INFO][/] Connected to the server ({self.__ip}:{self.__port}).') + except ConnectionRefusedError: + sys.stderr.write("Could not connect to the server. Please, check the ip and the port.\n") + sys.exit(1) async def send(self, message: str): self.writer.write(struct.pack('