unicex 0.1.14__py3-none-any.whl → 0.1.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ from typing import Any, Self
7
7
  import aiohttp
8
8
  from loguru import logger as _logger
9
9
 
10
+ from unicex.exceptions import ResponseError
10
11
  from unicex.types import LoggerLike, RequestMethod
11
12
 
12
13
 
@@ -168,13 +169,25 @@ class BaseClient:
168
169
  Возвращает:
169
170
  `dict | list`: Ответ API в формате JSON.
170
171
  """
171
- response.raise_for_status()
172
- result = await response.json()
172
+ try:
173
+ response.raise_for_status()
174
+ except Exception as e:
175
+ response_text = await response.text()
176
+ raise ResponseError(
177
+ f"HTTP error: {e}. Response: {response_text}. Status code: {response.status}"
178
+ ) from e
179
+
180
+ try:
181
+ result = await response.json()
182
+ except Exception as e:
183
+ raise ResponseError(
184
+ f"JSONDecodeError error: {e}. Response: {response.text}. Status code: {response.status}"
185
+ ) from e
173
186
 
174
187
  try:
175
188
  result_str: str = str(result)
176
189
  self._logger.debug(
177
- f"Response: {result_str[:100]} {'...' if len(result_str) > 100 else ''}"
190
+ f"Response: {result_str[:100]}{'...' if len(result_str) > 100 else ''}"
178
191
  )
179
192
  except Exception as e:
180
193
  self._logger.error(f"Error while log response: {e}")
@@ -71,7 +71,12 @@ class Websocket:
71
71
  self._running = True
72
72
 
73
73
  # Запускаем вебсокет
74
- await self._connect()
74
+ try:
75
+ await self._connect()
76
+ except Exception as e:
77
+ self._logger.error(f"Failed to connect to websocket: {e}")
78
+ self._running = False
79
+ raise
75
80
 
76
81
  async def stop(self) -> None:
77
82
  """Останавливает вебсокет и рабочие задачи."""
@@ -7,7 +7,7 @@ from typing import Any, Self
7
7
  import requests
8
8
  from loguru import logger as _logger
9
9
 
10
- from unicex.exceptions import UniCexException
10
+ from unicex.exceptions import ResponseError
11
11
  from unicex.types import LoggerLike, RequestMethod
12
12
 
13
13
 
@@ -144,24 +144,24 @@ class BaseClient:
144
144
  try:
145
145
  response.raise_for_status()
146
146
  except Exception as e:
147
- raise UniCexException(
147
+ raise ResponseError(
148
148
  f"HTTP error: {e}. Response: {response.text}. Status code: {response.status_code}"
149
149
  ) from e
150
150
 
151
151
  if not response.content:
152
- raise UniCexException(f"Empty response. Status code: {response.status_code}")
152
+ raise ResponseError(f"Empty response. Status code: {response.status_code}")
153
153
 
154
154
  try:
155
155
  result = response.json()
156
156
  except requests.exceptions.JSONDecodeError as e:
157
- raise UniCexException(
157
+ raise ResponseError(
158
158
  f"JSONDecodeError error: {e}. Response: {response.text}. Status code: {response.status_code}"
159
159
  ) from e
160
160
 
161
161
  try:
162
162
  result_str: str = str(result)
163
163
  self._logger.debug(
164
- f"Response: {result_str[:100]} {'...' if len(result_str) > 100 else ''}"
164
+ f"Response: {result_str[:100]}{'...' if len(result_str) > 100 else ''}"
165
165
  )
166
166
  except Exception as e:
167
167
  self._logger.error(f"Error while log response: {e}")
unicex/exceptions.py CHANGED
@@ -37,3 +37,10 @@ class QueueOverflowError(UniCexException):
37
37
  """Исключение, возникающее при переполнении очереди сообщений."""
38
38
 
39
39
  pass
40
+
41
+
42
+ @dataclass
43
+ class ResponseError(UniCexException):
44
+ """Исключение, возникающее при ошибке ответа."""
45
+
46
+ pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unicex
3
- Version: 0.1.14
3
+ Version: 0.1.15
4
4
  Summary: Unified Crypto Exchange API
5
5
  Author-email: LoveBloodAndDiamonds <ayazshakirzyanov27@gmail.com>
6
6
  License: BSD 3-Clause License
@@ -1,6 +1,6 @@
1
1
  unicex/__init__.py,sha256=LkRQxl60i91NZqLEOgOquh60tK73M31WaorxMUsS4-k,1372
2
2
  unicex/enums.py,sha256=wce1tN1qUIbx2seOzLh64kr0c5qyfji4FW7Qf2Crzp4,4215
3
- unicex/exceptions.py,sha256=PEJ1vysXQF-o_-UG0m3EB5TSw7SBwYO5dIysV-e9Hzc,1139
3
+ unicex/exceptions.py,sha256=Sl-MkTq1WhmGZbkjm-Hwn3Bn5dDH5V1Sr5QD_iOsEZw,1289
4
4
  unicex/extra.py,sha256=qgN0RH0g7V5Ve30bsYageiL3gAyxplU1wk7XLmzFXWo,6805
5
5
  unicex/mapper.py,sha256=Ymasn7zq5W0A1WEsIHO3st1FgeryvD7-ShWEi5kr9Mk,4658
6
6
  unicex/types.py,sha256=j74BbMxpraWg2Nncu6Fqtec0BPs_gRKiuIfR_A7DxEg,2171
@@ -15,10 +15,10 @@ unicex/_abc/sync/uni_client.py,sha256=ZKltLNHtinj1aepknk8Neh7EOPhJj0jHcBMkVHyG_a
15
15
  unicex/_abc/sync/uni_websocket_manager.py,sha256=MPGZfcC1FLcsRIvKj2yQHaK1nwSBo-KpSnIeuVcBE2c,9731
16
16
  unicex/_base/__init__.py,sha256=SMe2SLh94RNJbdI-w_CmaXA0479nCBJfbxOApKT5Iak,90
17
17
  unicex/_base/asyncio/__init__.py,sha256=ckqI6LVP3DHuIiLXKx67rJyG0SEEsPnBr8uk1Dw9cwg,114
18
- unicex/_base/asyncio/client.py,sha256=ExmQI4b7dLZcMEFWhzsLOs5BWMZGUF_THVsl6v_gMKw,7726
19
- unicex/_base/asyncio/websocket.py,sha256=4wGqBpdy3EcU9iVzGnxBjAO61RLfNgNyZ5F-Oo0tLBU,9845
18
+ unicex/_base/asyncio/client.py,sha256=ba87j1vpku5O24a9wsYQgf776OGUX85soLgUChBCwss,8223
19
+ unicex/_base/asyncio/websocket.py,sha256=VANQYJKVv75t85dL1JePO77IbdsHC6h8d9_8jjwCh-4,10016
20
20
  unicex/_base/sync/__init__.py,sha256=ckqI6LVP3DHuIiLXKx67rJyG0SEEsPnBr8uk1Dw9cwg,114
21
- unicex/_base/sync/client.py,sha256=MO6IArWWOvuHh9wLtHUwxr-0JMO3pqIvd52_h4OSWKI,6657
21
+ unicex/_base/sync/client.py,sha256=A-c-M4tXSlUX_4hlqjwL5zm_yjtRkAEqcqc3xw49T6A,6648
22
22
  unicex/_base/sync/websocket.py,sha256=tSTmZZFkbtcI1FWME__AkiMjcu3xNaRA0a0HoAnhkE0,10156
23
23
  unicex/binance/__init__.py,sha256=prW16sT_wNyu2Cx9w2Dndsu-kW6qsy_Cs5qP2XMBljo,446
24
24
  unicex/binance/adapter.py,sha256=f20XKuXdaWTBkFAfLgFXIuQoJwL_56-WMASzunV4TKo,14305
@@ -59,8 +59,8 @@ unicex/bybit/types.py,sha256=gCuzL_casy9kYQ33Mc5hiFW4MjTiEEU7xva38PkkfRA,8016
59
59
  unicex/bybit/uni_client.py,sha256=x8e3m4IH-tDGyjNk4hnM7KBrZFkLglF-RI8AuIhKJjc,6908
60
60
  unicex/bybit/websocket.py,sha256=K48uwoF2wjy1McGGfmUGj1Q9s3DvSabNLViqgBAG9YQ,159
61
61
  unicex/bybit/websocket_manager.py,sha256=3FdZn7WPAFnKsnknjDvbDnbpgH8xMj_4v-ksW81c9d4,902
62
- unicex-0.1.14.dist-info/licenses/LICENSE,sha256=lNNK4Vqak9cXm6qVJLhbqS7iR_BMj6k7fd7XQ6l1k54,1507
63
- unicex-0.1.14.dist-info/METADATA,sha256=-5i2Bg_VOhxazoqUwUTJCBrEW2_JCeiRtycdlpmwpz0,7158
64
- unicex-0.1.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
65
- unicex-0.1.14.dist-info/top_level.txt,sha256=_7rar-0OENIg4KRy6cgjWiebFYAJhjKEcMggAocGWG4,7
66
- unicex-0.1.14.dist-info/RECORD,,
62
+ unicex-0.1.15.dist-info/licenses/LICENSE,sha256=lNNK4Vqak9cXm6qVJLhbqS7iR_BMj6k7fd7XQ6l1k54,1507
63
+ unicex-0.1.15.dist-info/METADATA,sha256=m8NzKbMLshLZBqBq1PSWm4PWBDiQ2g00HI9D5ksE5bI,7158
64
+ unicex-0.1.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
65
+ unicex-0.1.15.dist-info/top_level.txt,sha256=_7rar-0OENIg4KRy6cgjWiebFYAJhjKEcMggAocGWG4,7
66
+ unicex-0.1.15.dist-info/RECORD,,