Add exception logging
This commit is contained in:
parent
47e8d8b33a
commit
cdc43f75ac
1 changed files with 144 additions and 182 deletions
18
great_ai/src/great_ai/great_ai/helper/use_http_exceptions.py
Normal file
18
great_ai/src/great_ai/great_ai/helper/use_http_exceptions.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from functools import wraps
|
||||
from typing import Any, Callable, Dict, List
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
def use_http_exceptions(func: Callable[..., Any]) -> Callable[..., Any]:
|
||||
@wraps(func)
|
||||
def wrapper(*args: List[Any], **kwargs: Dict[str, Any]) -> Any:
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"The following exception has occurred: {type(e).__name__}: {e}",
|
||||
)
|
||||
|
||||
return wrapper
|
||||
Loading…
Reference in a new issue