internal 0.1.32__py3-none-any.whl → 0.1.34__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.

Potentially problematic release.


This version of internal might be problematic. Click here for more details.

@@ -0,0 +1,20 @@
1
+ from fastapi import status
2
+ from .base_exception import InternalBaseException
3
+
4
+
5
+ class BadGatewayException(InternalBaseException):
6
+ code = "error_bad_gateway"
7
+ message = "Bad gateway"
8
+
9
+ def __init__(self, message: str = None, **kwargs):
10
+ _message = message or self.message
11
+ super().__init__(status.HTTP_502_BAD_GATEWAY, self.code, _message, **kwargs)
12
+
13
+
14
+ class GatewayTimeoutException(InternalBaseException):
15
+ code = "error_gateway_timeout"
16
+ message = "Gateway timeout"
17
+
18
+ def __init__(self, message: str = None, **kwargs):
19
+ _message = message or self.message
20
+ super().__init__(status.HTTP_504_GATEWAY_TIMEOUT, self.code, _message, **kwargs)
internal/http/requests.py CHANGED
@@ -2,11 +2,22 @@ import httpx
2
2
 
3
3
  from fastapi import FastAPI
4
4
 
5
+ from ..exception.internal_exception import GatewayTimeoutException, BadGatewayException
6
+
5
7
 
6
8
  async def async_request(app: FastAPI, method, url, **kwargs):
7
9
  timeout = httpx.Timeout(connect=app.state.config.REQUEST_CONN_TIMEOUT, read=app.state.config.REQUEST_READ_TIMEOUT,
8
10
  write=app.state.config.REQUEST_WRITE_TIMEOUT, pool=app.state.config.REQUEST_POOL_TIMEOUT)
9
11
 
10
- async with httpx.AsyncClient(timeout=timeout) as client:
11
- response = await client.request(method, url, **kwargs)
12
- return response
12
+ try:
13
+ async with httpx.AsyncClient(timeout=timeout) as client:
14
+ response = await client.request(method, url, **kwargs)
15
+ return response
16
+ except httpx.TimeoutException as exc:
17
+ app.state.logger.error(
18
+ f"async_request(), TimeoutException, exc: {exc}, url: {url}, method: {method}, kwargs: {kwargs}")
19
+ raise GatewayTimeoutException()
20
+ except Exception as exc:
21
+ app.state.logger.error(
22
+ f"async_request(), Exception, exc: {exc}, url: {url}, method: {method}, kwargs: {kwargs}")
23
+ raise BadGatewayException()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: internal
3
- Version: 0.1.32
3
+ Version: 0.1.34
4
4
  Summary:
5
5
  Author: Ray
6
6
  Author-email: ray@cruisys.com
@@ -5,12 +5,13 @@ internal/const.py,sha256=U1S9r7bjtHgad2oYQoHO19s8D4V0WDUG-L-haV4UaIw,1025
5
5
  internal/database.py,sha256=MyRLlb0W8FB8Odq0UQpN3R7OD3yUPWgJXsZRuDWQC_w,1010
6
6
  internal/exception/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  internal/exception/base_exception.py,sha256=U0ZXx1FOXydAnQQImznkeAdsKVC_YaukPWvJdWqEBfg,363
8
+ internal/exception/internal_exception.py,sha256=Q1h8GmaiSCNd050y28TVhrZXp-HWGaJqKZ_duW8pxrk,683
8
9
  internal/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
10
  internal/ext/amazon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
11
  internal/ext/amazon/aws/__init__.py,sha256=2YFjb-rHG1JaZGZiZffYDesgTAJjDshOqQbswOYzhP8,834
11
12
  internal/ext/amazon/aws/const.py,sha256=l4WMg5bKWujwOKABBkCO2zclNg3abnYOfbhD7DG8GsA,109
12
13
  internal/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- internal/http/requests.py,sha256=1LMKuUb1RU0tpJHektFhRkvGULyZg-XbIh1pmTS4vdY,492
14
+ internal/http/requests.py,sha256=ilifw2CcVpI_PiIG1rY4jyeE4wLY5A2jL1f2mguPx_Q,1026
14
15
  internal/http/responses.py,sha256=DADdRfyk8RerhGLVzqoy5OT2SeAX-po2X-aMqEvj_Eg,1498
15
16
  internal/interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
17
  internal/interface/base_interface.py,sha256=R5MmO5oa5-ORPV_adkegLVCwsVio2zFOuQFGiby3khs,340
@@ -18,6 +19,6 @@ internal/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
19
  internal/model/base_model.py,sha256=gNbixWuGiK8Tbe78wHuLneZ8p3fwMwQRKurBDrGoh6s,1874
19
20
  internal/model/operate.py,sha256=3mOs7eQ2CPnCB6i6UQBOp8VdTPmVnayaUFqUEDOKoTY,1493
20
21
  internal/utils.py,sha256=0SubS0iUhDvjSX1F4TykasA5-enYJzt2VH-f7_0BnjI,1509
21
- internal-0.1.32.dist-info/METADATA,sha256=MCSJvXWR9uXi21sjWbvAbPu0pQJjZZ-Fu7nc4Be2phk,625
22
- internal-0.1.32.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
23
- internal-0.1.32.dist-info/RECORD,,
22
+ internal-0.1.34.dist-info/METADATA,sha256=kH6bt8pEWIyjizpy4gIEVhJffe_Kx4QxcJj1xszP35g,625
23
+ internal-0.1.34.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
24
+ internal-0.1.34.dist-info/RECORD,,