mm-http 0.2.3__tar.gz → 0.2.4__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.
@@ -0,0 +1,2 @@
1
+ PROXY_SOCKS5=socks5://usr:pass@host:port
2
+ PROXY_HTTP=http://usr:pass@host:port
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mm-http
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Requires-Python: >=3.13
5
5
  Requires-Dist: aiohttp-socks~=0.11.0
6
6
  Requires-Dist: aiohttp~=3.13.3
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mm-http"
3
- version = "0.2.3"
3
+ version = "0.2.4"
4
4
  description = ""
5
5
  requires-python = ">=3.13"
6
6
  dependencies = [
@@ -1,5 +1,5 @@
1
- from .http_request import http_request
2
- from .http_request_sync import http_request_sync
1
+ from .request import http_request
2
+ from .request_sync import http_request_sync
3
3
  from .response import HttpResponse, TransportError, TransportErrorDetail
4
4
 
5
5
  __all__ = ["HttpResponse", "TransportError", "TransportErrorDetail", "http_request", "http_request_sync"]
@@ -82,6 +82,15 @@ class HttpResponse(BaseModel):
82
82
  """Check if response represents an error (has transport error or status >= 400)."""
83
83
  return self.transport_error is not None or (self.status_code is not None and self.status_code >= 400)
84
84
 
85
+ @property
86
+ def error_message(self) -> str | None:
87
+ """Get error message if transport_error is set or status_code >= 400, else None."""
88
+ if self.transport_error:
89
+ return f"{self.transport_error.type.value}: {self.transport_error.message}"
90
+ if self.status_code is not None and self.status_code >= 400:
91
+ return f"HTTP {self.status_code}"
92
+ return None
93
+
85
94
  def to_result_err[T](self, error: str | Exception | tuple[str, Exception] | None = None) -> Result[T]:
86
95
  """Create error Result[T] from HttpResponse with meaningful error message."""
87
96
  if error is not None:
@@ -135,3 +135,29 @@ def test_is_success():
135
135
 
136
136
  # Transport error
137
137
  assert not HttpResponse(transport_error=TransportErrorDetail(type=TransportError.TIMEOUT, message="timeout")).is_success()
138
+
139
+
140
+ def test_error_message():
141
+ """Test error_message property."""
142
+ # Transport error - returns "{type}: {message}"
143
+ assert (
144
+ HttpResponse(transport_error=TransportErrorDetail(type=TransportError.TIMEOUT, message="Request timed out")).error_message
145
+ == "timeout: Request timed out"
146
+ )
147
+
148
+ assert (
149
+ HttpResponse(
150
+ transport_error=TransportErrorDetail(type=TransportError.CONNECTION, message="Connection refused")
151
+ ).error_message
152
+ == "connection: Connection refused"
153
+ )
154
+
155
+ # HTTP error (status >= 400) - returns "HTTP {status}"
156
+ assert HttpResponse(status_code=404).error_message == "HTTP 404"
157
+ assert HttpResponse(status_code=500).error_message == "HTTP 500"
158
+ assert HttpResponse(status_code=400).error_message == "HTTP 400"
159
+
160
+ # Success (status < 400) - returns None
161
+ assert HttpResponse(status_code=200).error_message is None
162
+ assert HttpResponse(status_code=201).error_message is None
163
+ assert HttpResponse(status_code=399).error_message is None
@@ -511,7 +511,7 @@ wheels = [
511
511
 
512
512
  [[package]]
513
513
  name = "mm-http"
514
- version = "0.2.3"
514
+ version = "0.2.4"
515
515
  source = { editable = "." }
516
516
  dependencies = [
517
517
  { name = "aiohttp" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes