refactor: replace generic Exception handling with specific exceptions in various files

This commit is contained in:
Abhimanyu Saharan
2026-02-09 02:51:26 +05:30
parent 9714c7c24e
commit 9973b76463
4 changed files with 23 additions and 16 deletions

View File

@@ -71,14 +71,13 @@ async def get_session() -> AsyncGenerator[AsyncSession, None]:
try:
yield session
finally:
in_txn = False
try:
in_txn = bool(session.in_transaction())
except SQLAlchemyError:
logger.exception("Failed to inspect session transaction state.")
return
if not in_txn:
return
try:
await session.rollback()
except SQLAlchemyError:
logger.exception("Failed to rollback session after request error.")
if in_txn:
try:
await session.rollback()
except SQLAlchemyError:
logger.exception("Failed to rollback session after request error.")