finalsa-common-http-client 0.0.1__py3-none-any.whl → 0.0.3__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.
@@ -0,0 +1,13 @@
1
+ from ._shared import (
2
+ build_default_headers,
3
+ build_url,
4
+ ensure_scheme,
5
+ get_package_version,
6
+ merge_headers,
7
+ normalize_base_url,
8
+ )
9
+ from .async_client import BaseAsyncHttpClient
10
+ from .sync_client import BaseSyncHttpClient
11
+
12
+ __all__ = ["BaseSyncHttpClient", "BaseAsyncHttpClient", "normalize_base_url", "ensure_scheme", "build_url", "merge_headers", "build_default_headers", "get_package_version"]
13
+
@@ -4,7 +4,8 @@ from collections.abc import Mapping
4
4
  from typing import Any
5
5
 
6
6
  import aiohttp
7
- from aiohttp import ClientSession, ClientTimeout
7
+ from aiohttp import ClientResponseError, ClientSession, ClientTimeout
8
+ from finalsa.common.models import BaseDomainException
8
9
 
9
10
  from finalsa.http import _shared as shared
10
11
 
@@ -46,7 +47,8 @@ class BaseAsyncHttpClient:
46
47
  await self._ensure_session()
47
48
  return self
48
49
 
49
- async def __aexit__(self, exc_type, exc, tb) -> None: # type: ignore[override]
50
+ # type: ignore[override]
51
+ async def __aexit__(self, exc_type, exc, tb) -> None:
50
52
  await self.close()
51
53
 
52
54
  @property
@@ -100,17 +102,31 @@ class BaseAsyncHttpClient:
100
102
  )
101
103
  merged_headers = shared.merge_headers(self._default_headers, headers)
102
104
  request_timeout = self._normalize_timeout(timeout) or self._timeout
103
-
104
- return await session.request(
105
- method.upper(),
106
- resolved_url,
107
- headers=merged_headers,
108
- params=params,
109
- json=json,
110
- data=data,
111
- timeout=request_timeout,
112
- **kwargs,
113
- )
105
+ response = None
106
+ try:
107
+
108
+ response = await session.request(
109
+ method.upper(),
110
+ resolved_url,
111
+ headers=merged_headers,
112
+ params=params,
113
+ json=json,
114
+ data=data,
115
+ timeout=request_timeout,
116
+ **kwargs,
117
+ )
118
+ response.raise_for_status()
119
+ return response
120
+ except ClientResponseError as e:
121
+ if "Content-Type" in e.headers and e.headers["Content-Type"] == "application/json" and response is not None:
122
+ data = await response.json()
123
+ if data.get("message") and data.get("name"):
124
+ raise BaseDomainException(
125
+ message=data.get("message"),
126
+ response_code=response.status_code,
127
+ name=data.get("name")
128
+ ) from e
129
+ raise e
114
130
 
115
131
  async def get(self, path: str, **kwargs: Any) -> aiohttp.ClientResponse:
116
132
  return await self.request("GET", path, **kwargs)
@@ -139,7 +155,6 @@ class BaseAsyncHttpClient:
139
155
  self._session = aiohttp.ClientSession(
140
156
  timeout=self._timeout,
141
157
  trust_env=self._trust_env,
142
- raise_for_status=self._raise_for_status,
143
158
  )
144
159
  return self._session
145
160
 
@@ -4,6 +4,7 @@ from collections.abc import Mapping
4
4
  from typing import Any
5
5
 
6
6
  import requests
7
+ from finalsa.common.models import BaseDomainException
7
8
 
8
9
  from finalsa.http import _shared as shared
9
10
 
@@ -99,20 +100,30 @@ class BaseSyncHttpClient:
99
100
  )
100
101
  merged_headers = shared.merge_headers(self._default_headers, headers)
101
102
  request_timeout = timeout if timeout is not None else self._timeout
102
-
103
- response = session.request(
104
- method.upper(),
105
- resolved_url,
106
- headers=merged_headers,
107
- params=params,
108
- json=json,
109
- data=data,
110
- timeout=request_timeout,
111
- **kwargs,
112
- )
113
- if self._raise_for_status:
114
- response.raise_for_status()
115
- return response
103
+ try:
104
+ response = session.request(
105
+ method.upper(),
106
+ resolved_url,
107
+ headers=merged_headers,
108
+ params=params,
109
+ json=json,
110
+ data=data,
111
+ timeout=request_timeout,
112
+ **kwargs,
113
+ )
114
+ if self._raise_for_status:
115
+ response.raise_for_status()
116
+ return response
117
+ except requests.RequestException as e:
118
+ if e.response is not None and "Content-Type" in e.response.headers and e.response.headers["Content-Type"] == "application/json":
119
+ data = e.response.json()
120
+ if data.get("message") and data.get("name"):
121
+ raise BaseDomainException(
122
+ message=data.get("message"),
123
+ response_code=e.response.status_code,
124
+ name=data.get("name")
125
+ ) from e
126
+ raise e
116
127
 
117
128
  def get(self, path: str, **kwargs: Any) -> requests.Response:
118
129
  return self.request("GET", path, **kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: finalsa-common-http-client
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Summary: HTTP client library for common data types used in business applications
5
5
  Project-URL: Homepage, https://github.com/finalsa/finalsa-http-client
6
6
  Project-URL: Documentation, https://github.com/finalsa/finalsa-http-client#readme
@@ -36,17 +36,18 @@ Classifier: Intended Audience :: Developers
36
36
  Classifier: License :: OSI Approved :: MIT License
37
37
  Classifier: Operating System :: OS Independent
38
38
  Classifier: Programming Language :: Python :: 3
39
- Classifier: Programming Language :: Python :: 3.9
40
39
  Classifier: Programming Language :: Python :: 3.10
41
40
  Classifier: Programming Language :: Python :: 3.11
42
41
  Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Programming Language :: Python :: 3.13
43
43
  Classifier: Topic :: Software Development :: Internationalization
44
44
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
45
45
  Classifier: Topic :: Software Development :: Localization
46
46
  Classifier: Typing :: Typed
47
- Requires-Python: >=3.9
47
+ Requires-Python: >=3.10
48
48
  Requires-Dist: aiohttp>=3.10.5
49
49
  Requires-Dist: fastapi>=0.116.1
50
+ Requires-Dist: finalsa-common-models>=2.0.4
50
51
  Requires-Dist: finalsa-traceability>=1.0.1
51
52
  Requires-Dist: requests>=2.32.4
52
53
  Description-Content-Type: text/markdown
@@ -0,0 +1,10 @@
1
+ finalsa/http/__init__.py,sha256=tTeA_AP5gfFiXF783AxX5ZtSiQXxR1jkQ196J9YxXNk,419
2
+ finalsa/http/_shared.py,sha256=cYrac3Tjai7fv8KiyKi7Y5M5u88Q-lcTFS3XsEgy-IQ,2729
3
+ finalsa/http/async_client/__init__.py,sha256=L25WfVpUpPZlMv6-cgeWlNvmK5UJOhLZ1NOndcIsA9w,73
4
+ finalsa/http/async_client/base.py,sha256=OKaxKU1WDxpGi3bzBZxcjnIo7XcadKiPQ7fb93DBsvg,5994
5
+ finalsa/http/sync_client/__init__.py,sha256=ocLE6dofwYCD9_rJpIP1KhlIujRFcaJfhoaeXVrSCVE,59
6
+ finalsa/http/sync_client/base.py,sha256=9hGvci9USjmp9gG_uKAdcj-hsF79NJ3pvmNVlA5K6u8,5406
7
+ finalsa_common_http_client-0.0.3.dist-info/METADATA,sha256=atIi-1FGxjq-DaI4ih6MwDaRUzoKOE29IBuEo6i_EFo,9102
8
+ finalsa_common_http_client-0.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ finalsa_common_http_client-0.0.3.dist-info/licenses/LICENSE.md,sha256=_lu-V-f2tGID1BS2V_W6D2XWppBsylFF1J2KEpfIXN0,1084
10
+ finalsa_common_http_client-0.0.3.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- finalsa/http/_shared.py,sha256=cYrac3Tjai7fv8KiyKi7Y5M5u88Q-lcTFS3XsEgy-IQ,2729
2
- finalsa/http/async/__init__.py,sha256=L25WfVpUpPZlMv6-cgeWlNvmK5UJOhLZ1NOndcIsA9w,73
3
- finalsa/http/async/base.py,sha256=lAsouBWu6j811xyXm9-aAJvNscCnrYYrhzUVnELJC6c,5301
4
- finalsa/http/sync/__init__.py,sha256=ocLE6dofwYCD9_rJpIP1KhlIujRFcaJfhoaeXVrSCVE,59
5
- finalsa/http/sync/base.py,sha256=Z0CfY05BfnyMLDNEpGAjmZUx1tLznaqehTn81IsHTCA,4741
6
- finalsa_common_http_client-0.0.1.dist-info/METADATA,sha256=YaWFDN60zuIMtcAy029J-kXkEDY2dTwfqJJ5SBS6bHY,9056
7
- finalsa_common_http_client-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- finalsa_common_http_client-0.0.1.dist-info/licenses/LICENSE.md,sha256=_lu-V-f2tGID1BS2V_W6D2XWppBsylFF1J2KEpfIXN0,1084
9
- finalsa_common_http_client-0.0.1.dist-info/RECORD,,
File without changes
File without changes