[WIP] Exception handling
This commit is contained in:
@@ -11,18 +11,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
@api_library.route("/", methods=["POST"])
|
||||
def create_library():
|
||||
try:
|
||||
data = request.json
|
||||
except Exception as e:
|
||||
logger.debug(f"{e}")
|
||||
return { "status": "error", "error": "JSON Required" }, 415
|
||||
|
||||
data = request.json
|
||||
|
||||
with LibraryController() as controller:
|
||||
try:
|
||||
lib = Library(**data)
|
||||
library = controller.create(lib)
|
||||
except IntegrityError as e:
|
||||
logger.debug(f"DB Error Creating {e}")
|
||||
return { "status": "error", "error": f"{e.orig}" }, 400
|
||||
else:
|
||||
return { "status": "ok", "result": library.data.to_dict() }, 200
|
||||
lib = Library(**data)
|
||||
library = controller.create(lib)
|
||||
return { "status": "ok", "result": library.data.to_dict() }, 200
|
||||
Reference in New Issue
Block a user