tango-python 1.18.0__py3-none-any.whl → 1.18.1__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.
- tango/__init__.py +1 -1
- tango/client.py +31 -1
- {tango_python-1.18.0.dist-info → tango_python-1.18.1.dist-info}/METADATA +1 -1
- {tango_python-1.18.0.dist-info → tango_python-1.18.1.dist-info}/RECORD +7 -7
- {tango_python-1.18.0.dist-info → tango_python-1.18.1.dist-info}/WHEEL +0 -0
- {tango_python-1.18.0.dist-info → tango_python-1.18.1.dist-info}/entry_points.txt +0 -0
- {tango_python-1.18.0.dist-info → tango_python-1.18.1.dist-info}/licenses/LICENSE +0 -0
tango/__init__.py
CHANGED
tango/client.py
CHANGED
|
@@ -75,6 +75,31 @@ from tango.shapes import (
|
|
|
75
75
|
_COUNT_TYPE_KEY = "_tango_count_type"
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
def _error_body(response: httpx.Response) -> dict[str, Any]:
|
|
79
|
+
"""The JSON object an error response carries, or {} for an empty, non-JSON (a proxy's HTML page) or non-object body."""
|
|
80
|
+
try:
|
|
81
|
+
data = response.json() if response.content else {}
|
|
82
|
+
except ValueError:
|
|
83
|
+
return {}
|
|
84
|
+
return data if isinstance(data, dict) else {}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _error_reason(error_data: dict[str, Any]) -> str | None:
|
|
88
|
+
"""The server's own explanation from an error body, e.g. why a 403 refused the request.
|
|
89
|
+
|
|
90
|
+
The API sends either ``{"detail": "..."}`` or a structured body such as a tier gate's ``{"error": "...", "code": "tier_required", ...}``, sometimes nested under ``detail``.
|
|
91
|
+
"""
|
|
92
|
+
for body in (error_data, error_data.get("detail")):
|
|
93
|
+
if isinstance(body, str) and body:
|
|
94
|
+
return body
|
|
95
|
+
if isinstance(body, dict):
|
|
96
|
+
for key in ("error", "message", "detail"):
|
|
97
|
+
value = body.get(key)
|
|
98
|
+
if isinstance(value, str) and value:
|
|
99
|
+
return value
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
|
|
78
103
|
class TangoClient:
|
|
79
104
|
"""Tango API Client"""
|
|
80
105
|
|
|
@@ -232,8 +257,13 @@ class TangoClient:
|
|
|
232
257
|
detail = error_data.get("detail", "Rate limit exceeded")
|
|
233
258
|
raise TangoRateLimitError(detail, response.status_code, error_data)
|
|
234
259
|
elif not response.is_success:
|
|
260
|
+
error_data = _error_body(response)
|
|
261
|
+
reason = _error_reason(error_data)
|
|
262
|
+
message = f"API request failed with status {response.status_code}"
|
|
235
263
|
raise TangoAPIError(
|
|
236
|
-
f"
|
|
264
|
+
f"{message}: {reason}" if reason else message,
|
|
265
|
+
response.status_code,
|
|
266
|
+
error_data,
|
|
237
267
|
)
|
|
238
268
|
|
|
239
269
|
def _get(self, endpoint: str, params: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
tango/__init__.py,sha256=
|
|
2
|
-
tango/client.py,sha256=
|
|
1
|
+
tango/__init__.py,sha256=VqhIYcfNI56Lx8iBaT3qGYKpjaHxLWPpTC-fIujYxQA,2739
|
|
2
|
+
tango/client.py,sha256=awauFCq-gd-dCBAvDPeEBBgxwhuc_2ZzIhK-I7ki0U8,245711
|
|
3
3
|
tango/exceptions.py,sha256=oPiLCccBoWLK5SjHkzP-oI6mUD9twEeKSvEuLV5h01I,4224
|
|
4
4
|
tango/models.py,sha256=D9e8_AAAwVi1C4nOqdhWz-8ARBLPRsLGi8TDjucOMEY,72897
|
|
5
5
|
tango/shapes/__init__.py,sha256=7ea1WU74jp4znhNw-gXruag6m6eyPZtbVgbDFmFUWro,1072
|
|
@@ -16,8 +16,8 @@ tango/webhooks/cli.py,sha256=f_vQbJ2AeSQjKnQo7MxHFyUB2SAKcgHYmGQULS0isqQ,13858
|
|
|
16
16
|
tango/webhooks/receiver.py,sha256=5yhsVhlLyoxmOCGvmbynWAIlDB2OaCPVf1H4GA1SxmU,9279
|
|
17
17
|
tango/webhooks/signing.py,sha256=92Ee-0B6PR7ZkvY3Np3gzl88-mtfKkh-I7lxqCe2lGw,2374
|
|
18
18
|
tango/webhooks/simulate.py,sha256=g2Osa0FYU5mJuon07T2aUCtmkUoTEzsY261tlp76fF0,3165
|
|
19
|
-
tango_python-1.18.
|
|
20
|
-
tango_python-1.18.
|
|
21
|
-
tango_python-1.18.
|
|
22
|
-
tango_python-1.18.
|
|
23
|
-
tango_python-1.18.
|
|
19
|
+
tango_python-1.18.1.dist-info/METADATA,sha256=WL8McHrCjg-DuQ2-9FLyb9DyQZge8oSMnNXFCQhY_Nw,22824
|
|
20
|
+
tango_python-1.18.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
21
|
+
tango_python-1.18.1.dist-info/entry_points.txt,sha256=kGLUbglUjuaAqEFvOZ1QuSW0vWb6VeSpCIFKaOFkKoQ,50
|
|
22
|
+
tango_python-1.18.1.dist-info/licenses/LICENSE,sha256=j2kYVHMwTkoGn3ZNScnrdIueG0k2XzB_LCPFoyBc2wk,1064
|
|
23
|
+
tango_python-1.18.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|