Skip to content

Commit

Permalink
[SB] Catch websocket exception (#34859)
Browse files Browse the repository at this point in the history
* catch wb except

* Update sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_transport.py

* eh
  • Loading branch information
l0lawrence committed Apr 30, 2024
1 parent d2e868c commit 5fd2c52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ def _read(self, n, initial=False, buffer=None, _errnos=None): # pylint: disable
:return: The data read.
:rtype: bytearray
"""
from websocket import WebSocketTimeoutException
from websocket import WebSocketTimeoutException, WebSocketConnectionClosedException
try:
length = 0
view = buffer or memoryview(bytearray(n))
Expand All @@ -794,6 +794,8 @@ def _read(self, n, initial=False, buffer=None, _errnos=None): # pylint: disable
raise IOError("Websocket connection has already been closed.") from None
except WebSocketTimeoutException as wte:
raise TimeoutError('Websocket receive timed out (%s)' % wte) from wte
except (WebSocketConnectionClosedException, SSLError) as e:
raise ConnectionError('Websocket disconnected: %r' % e) from e
except:
self._read_buffer = BytesIO(view[:length])
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ def _read(self, n, initial=False, buffer=None, _errnos=None): # pylint: disable
:return: The data read.
:rtype: bytearray
"""
from websocket import WebSocketTimeoutException
from websocket import WebSocketTimeoutException, WebSocketConnectionClosedException
try:
length = 0
view = buffer or memoryview(bytearray(n))
Expand All @@ -794,6 +794,8 @@ def _read(self, n, initial=False, buffer=None, _errnos=None): # pylint: disable
raise IOError("Websocket connection has already been closed.") from None
except WebSocketTimeoutException as wte:
raise TimeoutError('Websocket receive timed out (%s)' % wte) from wte
except (WebSocketConnectionClosedException, SSLError) as e:
raise ConnectionError('Websocket disconnected: %r' % e) from e
except:
self._read_buffer = BytesIO(view[:length])
raise
Expand Down

0 comments on commit 5fd2c52

Please sign in to comment.