Fastapi refactor update

This commit is contained in:
Carlos-Mesquita
2024-10-01 19:31:01 +01:00
parent f92a803d96
commit 2a032c5aba
132 changed files with 22856 additions and 10309 deletions

View File

@@ -1,5 +1,5 @@
from .handle_exception import handle_exception
__all__ = [
"handle_exception"
]
from .handle_exception import handle_exception
__all__ = [
"handle_exception"
]

View File

@@ -1,15 +1,15 @@
import functools
from typing import Callable, Any
from fastapi import Response
def handle_exception(status_code: int = 500):
def decorator(func: Callable) -> Callable:
@functools.wraps(func)
async def wrapper(*args: Any, **kwargs: Any) -> Any:
try:
return await func(*args, **kwargs)
except Exception as e:
return Response(content=str(e), status_code=status_code)
return wrapper
return decorator
import functools
from typing import Callable, Any
from fastapi import Response
def handle_exception(status_code: int = 500):
def decorator(func: Callable) -> Callable:
@functools.wraps(func)
async def wrapper(*args: Any, **kwargs: Any) -> Any:
try:
return await func(*args, **kwargs)
except Exception as e:
return Response(content=str(e), status_code=status_code)
return wrapper
return decorator