wip: uvicorn logging conf to json

This commit is contained in:
Jakub Miazek
2024-08-17 10:45:51 +02:00
parent a58e98c4b1
commit 6f0b097d2d
9 changed files with 166 additions and 57 deletions

View File

@@ -5,6 +5,9 @@ from fastapi import HTTPException, status
from sqlalchemy.exc import SQLAlchemyError, IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import declared_attr, DeclarativeBase
from app.utils.logging import AppLogger
logger = AppLogger().get_logger()
class Base(DeclarativeBase):
@@ -26,6 +29,7 @@ class Base(DeclarativeBase):
db_session.add(self)
return await db_session.commit()
except SQLAlchemyError as ex:
logger.error(f"Error inserting instance of {self}: {repr(ex)}")
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
) from ex