20 lines
520 B
Python
20 lines
520 B
Python
import logging
|
|
from functools import wraps
|
|
|
|
from fastapi import HTTPException, status
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def raise_http_errors(func):
|
|
@wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
try:
|
|
return func(*args, **kwargs)
|
|
except Exception as e:
|
|
if isinstance(e, HTTPException):
|
|
raise
|
|
logger.error(e)
|
|
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Internal server error")
|
|
return wrapper
|