@@ -210,10 +210,10 @@ async def send_json(self, data: data_binding.JSONObject) -> None:
210
210
211
211
def _handle_other_message (self , message : aiohttp .WSMessage , / ) -> typing .NoReturn :
212
212
if message .type == aiohttp .WSMsgType .TEXT :
213
- raise errors .GatewayError ("Unexpected message type received TEXT, expected BINARY" )
213
+ raise errors .GatewayTransportError ("Unexpected message type received TEXT, expected BINARY" )
214
214
215
215
if message .type == aiohttp .WSMsgType .BINARY :
216
- raise errors .GatewayError ("Unexpected message type received BINARY, expected TEXT" )
216
+ raise errors .GatewayTransportError ("Unexpected message type received BINARY, expected TEXT" )
217
217
218
218
if message .type == aiohttp .WSMsgType .CLOSE :
219
219
close_code = int (message .data )
@@ -229,7 +229,8 @@ def _handle_other_message(self, message: aiohttp.WSMessage, /) -> typing.NoRetur
229
229
raise errors .GatewayConnectionError ("Socket has closed" )
230
230
231
231
# Assume exception for now.
232
- raise errors .GatewayError ("Unexpected websocket exception from gateway" ) from self ._ws .exception ()
232
+ reason = f"{ message .data !r} [extra={ message .extra !r} , type={ message .type } ]"
233
+ raise errors .GatewayTransportError (reason ) from self ._ws .exception ()
233
234
234
235
async def _receive_and_check_text (self ) -> str :
235
236
message = await self ._ws .receive ()
@@ -920,6 +921,9 @@ async def _keep_alive(self) -> None:
920
921
except errors .GatewayConnectionError as ex :
921
922
self ._logger .warning ("failed to communicate with server, reason was: %r. Will retry shortly" , ex .reason )
922
923
924
+ except errors .GatewayTransportError as ex :
925
+ self ._logger .error ("encountered transport error. Will try to reconnect shorty" , exc_info = ex )
926
+
923
927
except errors .GatewayServerClosedConnectionError as ex :
924
928
if not ex .can_reconnect :
925
929
self ._logger .info (
0 commit comments