[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

@@ -0,0 +1,2 @@
from .base import LibraryExceptionBase
from .exc_01001X_create import LibraryCreationException

View File

@@ -0,0 +1,18 @@
class LibraryExceptionBase(Exception):
def __init__(self, code, error):
self.code = code
self.error = error
def to_dict(self):
return {
"status": "error",
"code": self.code,
"error": self.error,
"status_code": 400
}
def __str__(self):
return f"ERROR {self.code}: {self.error}"
def __repr__(self):
return f"LibraryExceptionBase(code={self.code!r}, error={self.error!r})"

View File

@@ -0,0 +1,26 @@
from .base import LibraryExceptionBase
#010010
class LibraryCreationException(LibraryExceptionBase):
def __init__(self, name, error, object, data, status_code=400):
self.code = "010010"
self.name = name
self.error = error
self.object = object
self.data = data
self.status_code = status_code
def to_dict(self):
return {
"status": "error",
"name": self.name,
"code": self.code,
"error": self.error,
"object": self.object,
"data": self.data,
"status_code": self.status_code
}
def __repr__(self):
return f"LibraryCreationException(code={self.code!r}, error={self.error!r}), " \
f"object={self.object!r}, data={self.data!r}"