Skip to content

Commit

Permalink
Merge pull request #10 from truenas/NAS-130664
Browse files Browse the repository at this point in the history
NAS-130664 / 25.04 / Forward `WebSocketException`
  • Loading branch information
themylogin authored Aug 16, 2024
2 parents 76a4a29 + eaab1ce commit c1d48e9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions truenas_api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from collections import defaultdict
import errno
import logging
import os
import pickle
import pprint
import random
Expand All @@ -17,7 +16,7 @@
import ssl
from websocket import WebSocketApp
from websocket._abnf import STATUS_NORMAL
from websocket._exceptions import WebSocketConnectionClosedException
from websocket._exceptions import WebSocketException, WebSocketConnectionClosedException
from websocket._http import connect, proxy_info
from websocket._socket import sock_opt

Expand Down Expand Up @@ -155,6 +154,7 @@ def _on_message(self, app, data):

def _on_error(self, app, e):
logger.warning("Websocket client error: %r", e)
self.client._ws_connection_error = e

def _on_close(self, app, code, reason):
self.client.on_close(code, reason)
Expand Down Expand Up @@ -235,6 +235,7 @@ def __init__(self, uri=None, reserved_ports=False, py_exceptions=False, log_py_e
self._closed = Event()
self._connected = Event()
self._connection_error = None
self._ws_connection_error = None
self._ws = WSClient(
uri,
client=self,
Expand All @@ -245,6 +246,9 @@ def __init__(self, uri=None, reserved_ports=False, py_exceptions=False, log_py_e
self._connected.wait(10)
if not self._connected.is_set():
raise ClientException('Failed connection handshake')
if self._ws_connection_error is not None:
if isinstance(self._ws_connection_error, WebSocketException):
raise self._ws_connection_error
if self._connection_error is not None:
raise ClientException(self._connection_error)

Expand Down

0 comments on commit c1d48e9

Please sign in to comment.