[UPD] Exception handling

This commit is contained in:
2026-02-15 20:53:32 +01:00
parent 2a8a44e80b
commit 969333998c
17 changed files with 105 additions and 81 deletions

View File

@@ -6,7 +6,11 @@ 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 sqlalchemy.exc import NoResultFound
from .exceptions import LibraryCreationException
from .exceptions import LibraryReadException
from .exceptions import LibraryUpdateException
import logging
logging.basicConfig(level=logging.DEBUG)
@@ -67,7 +71,8 @@ class LibraryController:
self._library = libraries[0]
return True
return False
#CRUDS
def create(self, library:Library):
try:
self._library = create(self.session, library)
@@ -76,20 +81,35 @@ class LibraryController:
"Cannot create library",
f"{e.orig}",
"library",
str(library),
400
str(library)
)
return self
def read(self, _id):
self._library = read(self.session, _id, Library)
try:
self._library = read(self.session, _id, Library)
except NoResultFound as e:
raise LibraryReadException(
f"Cannot read Library with id {_id}",
f"{e}",
"library",
_id
)
return self
def read_all(self):
self._libraries = read_all(self.session, Library)
def update(self):
self.session.commit()
try:
self.session.commit()
except IntegrityError as e:
raise LibraryUpdateException(
f"Cannot update Library",
f"{e}",
"library",
None
)
def delete(self):
delete(self.session, self.data)