[WIP] Exception handling

This commit is contained in:
2026-02-15 17:39:21 +01:00
parent 7c3593d066
commit 2a8a44e80b
7 changed files with 103 additions and 15 deletions

View File

@@ -1,10 +1,13 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.exc import IntegrityError
from app.api.cruds.base import create, read, update, delete, read_all
from app.schema.library import Library
from ..db.config.config import get_engine_configuration
from .exceptions import LibraryCreationException
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
@@ -66,7 +69,16 @@ class LibraryController:
return False
def create(self, library:Library):
self._library = create(self.session, library)
try:
self._library = create(self.session, library)
except IntegrityError as e:
raise LibraryCreationException(
"Cannot create library",
f"{e.orig}",
"library",
str(library),
400
)
return self
def read(self, _id):