6
6
from websockets .client import WebSocketClientProtocol
7
7
from websockets .datastructures import Headers , HeadersLike
8
8
9
- from ...exceptions import TransportConnectionClosed , TransportProtocolError
9
+ from ...exceptions import TransportConnectionFailed , TransportProtocolError
10
10
from .connection import AdapterConnection
11
11
12
12
log = logging .getLogger ("gql.transport.common.adapters.websockets" )
@@ -70,7 +70,7 @@ async def connect(self) -> None:
70
70
try :
71
71
self .websocket = await websockets .client .connect (self .url , ** connect_args )
72
72
except Exception as e :
73
- raise TransportConnectionClosed ("Connect failed" ) from e
73
+ raise TransportConnectionFailed ("Connect failed" ) from e
74
74
75
75
self ._response_headers = self .websocket .response_headers
76
76
@@ -81,15 +81,15 @@ async def send(self, message: str) -> None:
81
81
message: String message to send
82
82
83
83
Raises:
84
- TransportConnectionClosed : If connection closed
84
+ TransportConnectionFailed : If connection closed
85
85
"""
86
86
if self .websocket is None :
87
- raise TransportConnectionClosed ("Connection is already closed" )
87
+ raise TransportConnectionFailed ("Connection is already closed" )
88
88
89
89
try :
90
90
await self .websocket .send (message )
91
91
except Exception as e :
92
- raise TransportConnectionClosed ("Connection was closed" ) from e
92
+ raise TransportConnectionFailed ("Connection was closed" ) from e
93
93
94
94
async def receive (self ) -> str :
95
95
"""Receive message from the WebSocket server.
@@ -98,18 +98,18 @@ async def receive(self) -> str:
98
98
String message received
99
99
100
100
Raises:
101
- TransportConnectionClosed : If connection closed
101
+ TransportConnectionFailed : If connection closed
102
102
TransportProtocolError: If protocol error or binary data received
103
103
"""
104
104
# It is possible that the websocket has been already closed in another task
105
105
if self .websocket is None :
106
- raise TransportConnectionClosed ("Connection is already closed" )
106
+ raise TransportConnectionFailed ("Connection is already closed" )
107
107
108
108
# Wait for the next websocket frame. Can raise ConnectionClosed
109
109
try :
110
110
data = await self .websocket .recv ()
111
111
except Exception as e :
112
- raise TransportConnectionClosed ("Connection was closed" ) from e
112
+ raise TransportConnectionFailed ("Connection was closed" ) from e
113
113
114
114
# websocket.recv() can return either str or bytes
115
115
# In our case, we should receive only str here
0 commit comments