mirror of
https://github.com/rommapp/romm.git
synced 2026-02-18 00:27:41 +01:00
27 lines
733 B
Python
27 lines
733 B
Python
import functools
|
|
|
|
from fastapi import HTTPException, status
|
|
from sqlalchemy.exc import ProgrammingError
|
|
|
|
from handler.database.base_handler import sync_session
|
|
from logger.logger import log
|
|
|
|
|
|
def begin_session(func):
|
|
@functools.wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
if hasattr(kwargs, "session"):
|
|
return func(*args, **kwargs)
|
|
|
|
try:
|
|
with sync_session.begin() as s:
|
|
kwargs["session"] = s
|
|
return func(*args, **kwargs)
|
|
except ProgrammingError as exc:
|
|
log.critical(str(exc))
|
|
raise HTTPException(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(exc)
|
|
) from exc
|
|
|
|
return wrapper
|