Skip to content

Commit

Permalink
add message type in the response as per suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Izquierdo committed Jan 8, 2024
1 parent 515ca53 commit ee459b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/aap_eda/wsapi/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/wsapi/test_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit ee459b0

Please sign in to comment.