dataify-sdk 1.4.1__tar.gz → 1.4.2__tar.gz

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.
Files changed (101) hide show
  1. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/PKG-INFO +2 -2
  2. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/README.md +1 -1
  3. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/docs/AI_WEB.md +2 -2
  4. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/pyproject.toml +1 -1
  5. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/__init__.py +1 -1
  6. dataify_sdk-1.4.2/src/dataify_sdk/errors.py +114 -0
  7. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/tests/test_client/test_web_monitor.py +3 -0
  8. dataify_sdk-1.4.2/tests/test_errors.py +68 -0
  9. dataify_sdk-1.4.1/src/dataify_sdk/errors.py +0 -67
  10. dataify_sdk-1.4.1/tests/test_errors.py +0 -43
  11. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/.gitignore +0 -0
  12. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/LICENSE +0 -0
  13. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/docs/WEB_MONITOR.md +0 -0
  14. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/examples/ai_web.py +0 -0
  15. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/examples/web_monitor.py +0 -0
  16. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/scripts/codegen.py +0 -0
  17. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/_codegen/__init__.py +0 -0
  18. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/_codegen/generate.py +0 -0
  19. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/ai_web.py +0 -0
  20. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/client.py +0 -0
  21. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/__init__.py +0 -0
  22. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/airbnbproduct.py +0 -0
  23. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazoncomment.py +0 -0
  24. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazonglobalproduct.py +0 -0
  25. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazonproduct.py +0 -0
  26. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazonproductlist.py +0 -0
  27. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazonseller.py +0 -0
  28. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingimages.py +0 -0
  29. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingmaps.py +0 -0
  30. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingnews.py +0 -0
  31. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingsearch.py +0 -0
  32. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingshopping.py +0 -0
  33. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingvideos.py +0 -0
  34. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bookinghotellist.py +0 -0
  35. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/chatgptanswer.py +0 -0
  36. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/crunchbasecompany.py +0 -0
  37. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/duckduckgosearch.py +0 -0
  38. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/ebayinfo.py +0 -0
  39. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/facebookcomment.py +0 -0
  40. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/facebookevent.py +0 -0
  41. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/facebookpost.py +0 -0
  42. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/facebookprofile.py +0 -0
  43. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/githubrepository.py +0 -0
  44. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/glassdoorcompany.py +0 -0
  45. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/glassdoorjoblistings.py +0 -0
  46. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleaimode.py +0 -0
  47. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlefinance.py +0 -0
  48. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleflights.py +0 -0
  49. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlehotels.py +0 -0
  50. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleimages.py +0 -0
  51. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlejobs.py +0 -0
  52. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlelens.py +0 -0
  53. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlelocal.py +0 -0
  54. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlemapcomment.py +0 -0
  55. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlemapdetails.py +0 -0
  56. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlemaps.py +0 -0
  57. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlenews.py +0 -0
  58. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlepatents.py +0 -0
  59. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleplay.py +0 -0
  60. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleplaystoreinformation.py +0 -0
  61. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleplaystorereviews.py +0 -0
  62. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlescholar.py +0 -0
  63. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlesearch.py +0 -0
  64. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleshopping.py +0 -0
  65. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleshoppinginfo.py +0 -0
  66. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googletrends.py +0 -0
  67. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlevideos.py +0 -0
  68. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/indeedcompaniesinfo.py +0 -0
  69. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/indeedjoblistings.py +0 -0
  70. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/instagramcomment.py +0 -0
  71. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/instagramprofiles.py +0 -0
  72. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/instagramreel.py +0 -0
  73. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/linkedincompanyinformation.py +0 -0
  74. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/linkedinjoblistingsinformation.py +0 -0
  75. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/redditcomment.py +0 -0
  76. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/redditposts.py +0 -0
  77. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/tiktokcomment.py +0 -0
  78. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/tiktokposts.py +0 -0
  79. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/tiktokprofiles.py +0 -0
  80. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/tiktokshop.py +0 -0
  81. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/twitterpost.py +0 -0
  82. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/twitterprofile.py +0 -0
  83. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/walmartproduct.py +0 -0
  84. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/yandexsearch.py +0 -0
  85. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubeaudio.py +0 -0
  86. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubecomment.py +0 -0
  87. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubeproduct.py +0 -0
  88. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubeprofiles.py +0 -0
  89. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubetranscript.py +0 -0
  90. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubevideo.py +0 -0
  91. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubevideopost.py +0 -0
  92. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/zillowproduct.py +0 -0
  93. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/src/dataify_sdk/web_monitor.py +0 -0
  94. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/tests/__init__.py +0 -0
  95. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/tests/conftest.py +0 -0
  96. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/tests/test_client/__init__.py +0 -0
  97. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/tests/test_client/test_ai_web.py +0 -0
  98. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/tests/test_client/test_http_client.py +0 -0
  99. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/tests/test_tools/__init__.py +0 -0
  100. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/tests/test_tools/test_codegen.py +0 -0
  101. {dataify_sdk-1.4.1 → dataify_sdk-1.4.2}/tests/test_tools/test_tool_modules.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: dataify-sdk
3
- Version: 1.4.1
3
+ Version: 1.4.2
4
4
  Summary: Python SDK that calls the Dataify upstream REST API directly (no MCP layer) for web scrapers and search engines.
5
5
  Project-URL: Homepage, https://dashboard.dataify.com
6
6
  Project-URL: Repository, https://github.com/dataify-server/dataify-sdk-python
@@ -151,7 +151,7 @@ client = DataifyClient(token="YOUR_TOKEN")
151
151
  try:
152
152
  result = google_search(q="pizza", client=client)
153
153
  except DataifyAPIError as e:
154
- print(f"上游返回错误 HTTP {e.status_code}: {e.body}")
154
+ print(f"上游返回错误 HTTP {e.status_code}: {e.code} {e.message}")
155
155
  except DataifyConnectionError:
156
156
  print("无法连接 Dataify 上游")
157
157
  ```
@@ -126,7 +126,7 @@ client = DataifyClient(token="YOUR_TOKEN")
126
126
  try:
127
127
  result = google_search(q="pizza", client=client)
128
128
  except DataifyAPIError as e:
129
- print(f"上游返回错误 HTTP {e.status_code}: {e.body}")
129
+ print(f"上游返回错误 HTTP {e.status_code}: {e.code} {e.message}")
130
130
  except DataifyConnectionError:
131
131
  print("无法连接 Dataify 上游")
132
132
  ```
@@ -171,7 +171,7 @@ if result.request_id:
171
171
  ## 错误处理
172
172
 
173
173
  - 未配置网关:抛出 `DataifyMissingAIWebBaseUrlError`,请求不会发出。
174
- - 上游返回非 2xx:抛出 `DataifyAPIError`,包含 `status_code` 和 `body`。
174
+ - 上游返回非 2xx:抛出 `DataifyAPIError`,包含 `status_code`、解析后的 `code` / `message`,以及原始 `body`。
175
175
  - 缺少 `unique_id`、`query` 或 `url`:抛出 `ValueError`。
176
176
  - `formats` 非法或重复:抛出 `ValueError`。
177
177
 
@@ -185,5 +185,5 @@ try:
185
185
  except DataifyMissingAIWebBaseUrlError:
186
186
  print("AI Web 网关不可用")
187
187
  except DataifyAPIError as exc:
188
- print(f"AI Web 返回错误 HTTP {exc.status_code}: {exc.body}")
188
+ print(f"AI Web 返回错误 HTTP {exc.status_code}: {exc.code} {exc.message}")
189
189
  ```
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "dataify-sdk"
7
- version = "1.4.1"
7
+ version = "1.4.2"
8
8
  description = "Python SDK that calls the Dataify upstream REST API directly (no MCP layer) for web scrapers and search engines."
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -48,7 +48,7 @@ from dataify_sdk.errors import (
48
48
  DataifyValueError,
49
49
  )
50
50
 
51
- __version__ = "1.4.1"
51
+ __version__ = "1.4.2"
52
52
 
53
53
 
54
54
 
@@ -0,0 +1,114 @@
1
+ """Exceptions raised by the Dataify SDK."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any
7
+
8
+
9
+ class DataifyError(Exception):
10
+ """Base class for all Dataify SDK errors."""
11
+
12
+
13
+ class DataifyValueError(DataifyError, ValueError):
14
+ """Raised when SDK input validation fails."""
15
+
16
+
17
+ class DataifyAPIError(DataifyError):
18
+ """Raised when the Dataify upstream API returns an error.
19
+
20
+ Attributes
21
+ ----------
22
+ message:
23
+ Parsed upstream message when available, otherwise the request-level
24
+ fallback message.
25
+ code:
26
+ Parsed upstream error code, for example ``INVALID_API_KEY``.
27
+ api_message:
28
+ Parsed upstream message; ``None`` when the body has no usable message.
29
+ context_message:
30
+ Request-level message supplied by the SDK before parsing the body.
31
+ status_code:
32
+ HTTP status code returned by the upstream (``None`` for network errors).
33
+ body:
34
+ Decoded response body (or error text) returned by the upstream.
35
+ """
36
+
37
+ def __init__(
38
+ self,
39
+ message: str,
40
+ status_code: int | None = None,
41
+ body: str | bytes | None = None,
42
+ ) -> None:
43
+ decoded_body = _decode_error_body(body)
44
+ code, api_message = _parse_error_body(decoded_body)
45
+ self.context_message = message
46
+ self.status_code = status_code
47
+ self.body = decoded_body
48
+ self.code = code
49
+ self.api_message = api_message
50
+ self.message = api_message or message
51
+ super().__init__(self.message)
52
+
53
+ def __str__(self) -> str:
54
+ if self.status_code is not None:
55
+ return f"{self.message} (HTTP {self.status_code})"
56
+ return self.message
57
+
58
+
59
+ def _decode_error_body(body: str | bytes | None) -> str | None:
60
+ if body is None:
61
+ return None
62
+ if isinstance(body, bytes):
63
+ return body.decode("utf-8", errors="replace")
64
+ return body
65
+
66
+
67
+ def _parse_error_body(body: str | None) -> tuple[str | None, str | None]:
68
+ if not body or not body.strip():
69
+ return None, None
70
+ try:
71
+ payload: Any = json.loads(body)
72
+ except (TypeError, ValueError):
73
+ return None, None
74
+ if not isinstance(payload, dict):
75
+ return None, None
76
+
77
+ raw_code = payload.get("code")
78
+ code = str(raw_code).strip() if raw_code is not None else ""
79
+ if not code:
80
+ code = None
81
+
82
+ raw_message = payload.get("message")
83
+ if raw_message is None:
84
+ data = payload.get("data")
85
+ if isinstance(data, str):
86
+ raw_message = data
87
+ elif isinstance(data, dict):
88
+ raw_message = data.get("message")
89
+ message = str(raw_message).strip() if raw_message is not None else ""
90
+ if not message:
91
+ message = None
92
+ return code, message
93
+
94
+
95
+ class DataifyConnectionError(DataifyError):
96
+ """Raised when the HTTP request to the Dataify upstream cannot be completed."""
97
+
98
+
99
+ class DataifyTimeoutError(DataifyError):
100
+ """Raised when the HTTP request to the Dataify upstream times out."""
101
+
102
+
103
+ class DataifyMissingAIWebBaseUrlError(DataifyError):
104
+ """Raised when an AI Web request has no usable gateway base URL.
105
+
106
+ The SDK defaults to ``https://aiwebapi.dataify.com``. This error only
107
+ occurs when the client's AI Web base URL is explicitly cleared.
108
+ """
109
+
110
+ def __init__(self) -> None:
111
+ super().__init__(
112
+ "AI Web base URL is empty: pass ai_web_base_url=... "
113
+ "or set AI_WEB_API_BASE_URL."
114
+ )
@@ -333,3 +333,6 @@ def test_http_error_propagates(monkeypatch):
333
333
  _client().web_monitor.list_jobs()
334
334
 
335
335
  assert exc.value.status_code == 401
336
+ assert exc.value.code == "INVALID_API_KEY"
337
+ assert exc.value.api_message is None
338
+ assert exc.value.message.startswith("Dataify API request failed:")
@@ -0,0 +1,68 @@
1
+ """Tests for SDK exception formatting."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import pytest
6
+
7
+ from dataify_sdk import (
8
+ DataifyAPIError,
9
+ DataifyConnectionError,
10
+ DataifyError,
11
+ DataifyMissingAIWebBaseUrlError,
12
+ DataifyTimeoutError,
13
+ )
14
+
15
+
16
+ def test_dataify_api_error_parses_code_and_message():
17
+ error = DataifyAPIError(
18
+ "request failed",
19
+ 401,
20
+ '{"code": "INVALID_API_KEY", "message": "invalid token"}',
21
+ )
22
+
23
+ assert error.code == "INVALID_API_KEY"
24
+ assert error.api_message == "invalid token"
25
+ assert error.message == "invalid token"
26
+ assert error.context_message == "request failed"
27
+ assert error.body == '{"code": "INVALID_API_KEY", "message": "invalid token"}'
28
+ assert str(error) == "invalid token (HTTP 401)"
29
+
30
+
31
+ def test_dataify_api_error_parses_legacy_data_message():
32
+ error = DataifyAPIError("request failed", 400, '{"code": 400, "data": "验证失败"}')
33
+
34
+ assert error.code == "400"
35
+ assert error.api_message == "验证失败"
36
+ assert error.message == "验证失败"
37
+
38
+
39
+ def test_dataify_api_error_falls_back_for_non_json_body():
40
+ error = DataifyAPIError("request failed", 500, "upstream unavailable")
41
+
42
+ assert error.code is None
43
+ assert error.api_message is None
44
+ assert error.message == "request failed"
45
+ assert str(error) == "request failed (HTTP 500)"
46
+
47
+
48
+ def test_dataify_api_error_str_without_status():
49
+ error = DataifyAPIError("boom")
50
+
51
+ assert str(error) == "boom"
52
+
53
+
54
+ @pytest.mark.parametrize(
55
+ "error",
56
+ [
57
+ DataifyError("boom"),
58
+ DataifyAPIError("boom"),
59
+ DataifyConnectionError("boom"),
60
+ DataifyTimeoutError("boom"),
61
+ DataifyMissingAIWebBaseUrlError(),
62
+ ],
63
+ )
64
+ def test_every_dataify_error_can_be_printed(error):
65
+ rendered = str(error)
66
+
67
+ assert isinstance(rendered, str)
68
+ assert rendered
@@ -1,67 +0,0 @@
1
- """Exceptions raised by the Dataify SDK."""
2
-
3
- from __future__ import annotations
4
-
5
-
6
- class DataifyError(Exception):
7
- """Base class for all Dataify SDK errors."""
8
-
9
-
10
- class DataifyValueError(DataifyError, ValueError):
11
- """Raised when SDK input validation fails."""
12
-
13
-
14
- class DataifyAPIError(DataifyError):
15
- """Raised when the Dataify upstream API returns an error.
16
-
17
- Attributes
18
- ----------
19
- message:
20
- Human-readable error message.
21
- status_code:
22
- HTTP status code returned by the upstream (``None`` for network errors).
23
- body:
24
- Raw response body (or error text) returned by the upstream.
25
- """
26
-
27
-
28
-
29
- def __init__(
30
- self,
31
- message: str,
32
- status_code: int | None = None,
33
- body: str | None = None,
34
- ) -> None:
35
- self.message = message
36
- self.status_code = status_code
37
- self.body = body
38
- super().__init__(message)
39
-
40
-
41
-
42
- def __str__(self) -> str:
43
- if self.status_code is not None:
44
- return f"{self.message} (HTTP {self.status_code})"
45
- return self.message
46
-
47
-
48
- class DataifyConnectionError(DataifyError):
49
- """Raised when the HTTP request to the Dataify upstream cannot be completed."""
50
-
51
-
52
- class DataifyTimeoutError(DataifyError):
53
- """Raised when the HTTP request to the Dataify upstream times out."""
54
-
55
-
56
- class DataifyMissingAIWebBaseUrlError(DataifyError):
57
- """Raised when an AI Web request has no usable gateway base URL.
58
-
59
- The SDK defaults to ``https://aiwebapi.dataify.com``. This error only
60
- occurs when the client's AI Web base URL is explicitly cleared.
61
- """
62
-
63
- def __init__(self) -> None:
64
- super().__init__(
65
- "AI Web base URL is empty: pass ai_web_base_url=... "
66
- "or set AI_WEB_API_BASE_URL."
67
- )
@@ -1,43 +0,0 @@
1
- """Tests for SDK exception formatting."""
2
-
3
- from __future__ import annotations
4
-
5
- import pytest
6
-
7
- from dataify_sdk import (
8
- DataifyAPIError,
9
- DataifyConnectionError,
10
- DataifyError,
11
- DataifyMissingAIWebBaseUrlError,
12
- DataifyTimeoutError,
13
- )
14
-
15
-
16
- def test_dataify_api_error_str_includes_message_and_status():
17
- error = DataifyAPIError("boom", 401, '{"message": "invalid"}')
18
-
19
- assert error.message == "boom"
20
- assert str(error) == "boom (HTTP 401)"
21
-
22
-
23
- def test_dataify_api_error_str_without_status():
24
- error = DataifyAPIError("boom")
25
-
26
- assert str(error) == "boom"
27
-
28
-
29
- @pytest.mark.parametrize(
30
- "error",
31
- [
32
- DataifyError("boom"),
33
- DataifyAPIError("boom"),
34
- DataifyConnectionError("boom"),
35
- DataifyTimeoutError("boom"),
36
- DataifyMissingAIWebBaseUrlError(),
37
- ],
38
- )
39
- def test_every_dataify_error_can_be_printed(error):
40
- rendered = str(error)
41
-
42
- assert isinstance(rendered, str)
43
- assert rendered
File without changes
File without changes