From ee459b0abd2a6dc6a945e2fb0fef012aa29e34d5 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 8 Jan 2024 17:51:03 +0100 Subject: [PATCH] add message type in the response as per suggestion --- src/aap_eda/wsapi/consumers.py | 4 +++- tests/integration/wsapi/test_consumer.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/aap_eda/wsapi/consumers.py b/src/aap_eda/wsapi/consumers.py index ce8995b0c..936a6b76d 100644 --- a/src/aap_eda/wsapi/consumers.py +++ b/src/aap_eda/wsapi/consumers.py @@ -90,11 +90,13 @@ async def receive(self, text_data=None, bytes_data=None): data = json.loads(text_data) logger.debug(f"AnsibleRulebookConsumer received: {data}") + msg_type = data.get("type") try: msg_type = MessageType(data.get("type")) except ValueError: logger.error(f"Unsupported message type: {data}") - await self.send('{"error": "unsupported message type"}') + payload = {"error": f"unsupported message type: {msg_type}"} + await self.send(text_data=json.dumps(payload)) await self.close() return diff --git a/tests/integration/wsapi/test_consumer.py b/tests/integration/wsapi/test_consumer.py index b8839df71..d28d4a2ad 100644 --- a/tests/integration/wsapi/test_consumer.py +++ b/tests/integration/wsapi/test_consumer.py @@ -78,7 +78,7 @@ async def test_valid_websocket_route_wrong_type(): await communicator.send_to(text_data='{"type": "unsuported_type"}') response = await communicator.receive_from() assert ( - response == '{"error": "unsupported message type"}' + response == '{"error": "unsupported message type: unsuported_type"}' ), "Unexpected error message" await communicator.disconnect()