[UPD] Exception handling
This commit is contained in:
21
app/controller/functions/update_item_key.py
Normal file
21
app/controller/functions/update_item_key.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from ..exceptions import LibraryDataExection
|
||||
from ...schema.library import Base
|
||||
|
||||
def update_item_key(obj:Base, key, value):
|
||||
if key == "id":
|
||||
raise LibraryDataExection(
|
||||
"id is not updatable",
|
||||
"The key ID is not Updatable",
|
||||
obj.__class__,
|
||||
{key: value}
|
||||
)
|
||||
try:
|
||||
obj.__getattribute__(key)
|
||||
except AttributeError:
|
||||
raise LibraryDataExection(
|
||||
f"{key} not in {obj.__class__}",
|
||||
f"The key {key} is not in {obj.__class__}",
|
||||
obj.__class__,
|
||||
{key: value}
|
||||
)
|
||||
obj.__setattr__(key, value)
|
||||
Reference in New Issue
Block a user