Fastapi refactor update
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from .handle_exception import handle_exception
|
||||
|
||||
__all__ = [
|
||||
"handle_exception"
|
||||
]
|
||||
from .handle_exception import handle_exception
|
||||
|
||||
__all__ = [
|
||||
"handle_exception"
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user