Skip to content

Commit

Permalink
Simplify exceptions raised by send_close.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Aug 12, 2021
1 parent 1f46200 commit 90a20f5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/websockets/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def send_close(self, code: Optional[int] = None, reason: str = "") -> None:
raise ProtocolError("expected a continuation frame")
if code is None:
if reason != "":
raise ValueError("cannot send a reason without a code")
raise ProtocolError("cannot send a reason without a code")
close = Close(1005, "")
data = b""
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,13 +865,13 @@ def test_server_receives_close_with_code_and_reason(self):

def test_client_sends_close_with_reason_only(self):
client = Connection(Side.CLIENT)
with self.assertRaises(ValueError) as raised:
with self.assertRaises(ProtocolError) as raised:
client.send_close(reason="going away")
self.assertEqual(str(raised.exception), "cannot send a reason without a code")

def test_server_sends_close_with_reason_only(self):
server = Connection(Side.SERVER)
with self.assertRaises(ValueError) as raised:
with self.assertRaises(ProtocolError) as raised:
server.send_close(reason="OK")
self.assertEqual(str(raised.exception), "cannot send a reason without a code")

Expand Down

0 comments on commit 90a20f5

Please sign in to comment.