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 CHANGED
@@ -62,7 +62,7 @@ from .webhooks import (
62
62
  )
63
63
  from .webhooks.receiver import Delivery, WebhookReceiver
64
64
 
65
- __version__ = "1.18.0"
65
+ __version__ = "1.18.1"
66
66
  __all__ = [
67
67
  "TangoClient",
68
68
  "TangoAPIError",
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"API request failed with status {response.status_code}", response.status_code
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,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: tango-python
3
- Version: 1.18.0
3
+ Version: 1.18.1
4
4
  Summary: Python SDK for the Tango API
5
5
  Project-URL: Homepage, https://github.com/makegov/tango-python
6
6
  Project-URL: Documentation, https://docs.makegov.com/tango-python
@@ -1,5 +1,5 @@
1
- tango/__init__.py,sha256=KCJAQuPFMIOevwV29hvLdspZrvfMFvj8eNp8CLdZFMU,2739
2
- tango/client.py,sha256=V7wlznIjQgO0puJcATTLlbB5KK9245TcPUwrK-29X6Q,244464
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.0.dist-info/METADATA,sha256=JsBA_p7qMZTXV9SqN4XuGZztVFGuAH94kE8ye1LK9rA,22824
20
- tango_python-1.18.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
21
- tango_python-1.18.0.dist-info/entry_points.txt,sha256=kGLUbglUjuaAqEFvOZ1QuSW0vWb6VeSpCIFKaOFkKoQ,50
22
- tango_python-1.18.0.dist-info/licenses/LICENSE,sha256=j2kYVHMwTkoGn3ZNScnrdIueG0k2XzB_LCPFoyBc2wk,1064
23
- tango_python-1.18.0.dist-info/RECORD,,
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,,