File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -133,16 +133,21 @@ async def _send_bytes_exc(self, data: bytes):
133133 await self .ws .send_bytes (data )
134134 except (websockets .exceptions .ConnectionClosed , starlette .websockets .WebSocketDisconnect , RuntimeError ) as e :
135135 # starlette throws a RuntimeError once you call send after the connection is closed
136- raise websocket .WebSocketDisconnect () from e
136+ if isinstance (e , RuntimeError ) and "close message" in repr (e ):
137+ raise websocket .WebSocketDisconnect () from e
138+ else :
139+ raise
137140
138141 async def _send_text_exc (self , data : str ):
139142 # make sures we catch the starlette/websockets specific exception
140143 # and re-raise it as a websocket.WebSocketDisconnect
141144 try :
142145 await self .ws .send_text (data )
143146 except (websockets .exceptions .ConnectionClosed , starlette .websockets .WebSocketDisconnect , RuntimeError ) as e :
144- # starlette throws a RuntimeError once you call send after the connection is closed
145- raise websocket .WebSocketDisconnect () from e
147+ if isinstance (e , RuntimeError ) and "close message" in repr (e ):
148+ raise websocket .WebSocketDisconnect () from e
149+ else :
150+ raise
146151
147152 def close (self ):
148153 if self .portal is None :
You can’t perform that action at this time.
0 commit comments