fastapi-basic 0.0.10__py3-none-any.whl → 0.0.11__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 fastapi-basic might be problematic. Click here for more details.

@@ -3,13 +3,15 @@ from functools import lru_cache
3
3
  import os, dotenv
4
4
 
5
5
  import watchtower
6
- from fastapi import FastAPI, Request
6
+ from fastapi import FastAPI, HTTPException, Request
7
+ from fastapi.responses import JSONResponse
7
8
  from fastapi.middleware.cors import CORSMiddleware
8
9
  from starlette.concurrency import iterate_in_threadpool
9
10
  import logging
10
11
 
11
- from .ext.aws import init_app as init_aws_app
12
12
  from .const import LOG_DEFAULT_LOGGER_NAME, LOG_FMT
13
+ from .ext.aws import init_app as init_aws_app
14
+ from .exception.base_exception import InternalBaseException
13
15
  from .utils import update_dict_with_cast
14
16
 
15
17
  class BaseFactory(metaclass=ABCMeta):
@@ -66,6 +68,17 @@ class BaseFactory(metaclass=ABCMeta):
66
68
  app.state.aws_session = init_aws_app(app)
67
69
  self.__setup_aws_cloud_log(app)
68
70
 
71
+ @app.exception_handler(InternalBaseException)
72
+ async def http_exception_handler(request: Request, exc: InternalBaseException):
73
+ return JSONResponse(
74
+ status_code=exc.status_code,
75
+ content={
76
+ "code": exc.detail["code"],
77
+ "message": exc.detail["message"],
78
+ "data": exc.detail["data"]
79
+ }
80
+ )
81
+
69
82
  @app.middleware("http")
70
83
  async def handle_request_headers(request: Request, call_next):
71
84
  body = await request.body()
File without changes
@@ -0,0 +1,13 @@
1
+ from fastapi import HTTPException
2
+ from fastapi import status
3
+
4
+
5
+ class InternalBaseException(HTTPException):
6
+ def __init__(self, status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR, code: str = "internal_server_error",
7
+ message: str = "Internal server error", **kwargs):
8
+ detail = {
9
+ "code": code,
10
+ "message": message,
11
+ "data": kwargs,
12
+ }
13
+ super().__init__(status_code=status_code, detail=detail)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi_basic
3
- Version: 0.0.10
3
+ Version: 0.0.11
4
4
  Summary: A short description of your module
5
5
  Home-page: https://github.com/szx21023/fastapi-base
6
6
  Author: szx21023
@@ -1,12 +1,14 @@
1
1
  fastapi_basic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  fastapi_basic/base_config.py,sha256=nimiiK5LRY9kmx3dBDbN7teO4R8E423-c2iyq9WMcCg,442
3
- fastapi_basic/base_factory.py,sha256=wrQ6YYyqyEme7Hzkc_4HSddQzFZdE8GUsmUQsORTkI4,3255
3
+ fastapi_basic/base_factory.py,sha256=xrM4tbKjrhtqpzP2hupGJxiNeGsDnXfMYe8urOcq-ss,3801
4
4
  fastapi_basic/const.py,sha256=UA7-Eefu_dbWpbFn09Ei_BPb903SExnCgVbnm8_3ALE,99
5
5
  fastapi_basic/utils.py,sha256=8ympyQIXsKkxLILTI_7ug85vmKWYKqX0mpADjgHekgU,306
6
+ fastapi_basic/exception/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ fastapi_basic/exception/base_exception.py,sha256=xkpvAI8G96sqXqHgQC_rs2ZPL1liwKVXbXBIPF_8HPQ,473
6
8
  fastapi_basic/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
9
  fastapi_basic/ext/aws/__init__.py,sha256=N_cwnbv1N-F1SY6NenBOTZe20zGaKFu3UXAu17hFAXY,816
8
10
  fastapi_basic/ext/aws/const.py,sha256=Mmb6lo11aZZDAVy-nK-v_JxtVPPKYUo9GB4ihH7XYuM,68
9
- fastapi_basic-0.0.10.dist-info/METADATA,sha256=cRMHpw2uH7Ub-vDyQogQmPu_vNDMt5Bx_3MG7aaYLBg,1741
10
- fastapi_basic-0.0.10.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
11
- fastapi_basic-0.0.10.dist-info/top_level.txt,sha256=Q9PdwWxaB4dy135MQHiroRYOqArdUSaIeEkzYinN6W0,14
12
- fastapi_basic-0.0.10.dist-info/RECORD,,
11
+ fastapi_basic-0.0.11.dist-info/METADATA,sha256=rOAar0q0sPQKOxfkqrdnsKywYbJHMkmu9XJJLcWLsbA,1741
12
+ fastapi_basic-0.0.11.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
13
+ fastapi_basic-0.0.11.dist-info/top_level.txt,sha256=Q9PdwWxaB4dy135MQHiroRYOqArdUSaIeEkzYinN6W0,14
14
+ fastapi_basic-0.0.11.dist-info/RECORD,,