From 976d9df09d0ffca61be26f58553d7f4a73ffc827 Mon Sep 17 00:00:00 2001 From: stefanogoldoni Date: Sat, 15 May 2021 11:11:45 +0200 Subject: [PATCH] aggiunte exceptions --- .../repository/conditions/repository_conditions.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nest_backend/routes/repository/conditions/repository_conditions.py b/nest_backend/routes/repository/conditions/repository_conditions.py index 26382b4..d6cb8c2 100644 --- a/nest_backend/routes/repository/conditions/repository_conditions.py +++ b/nest_backend/routes/repository/conditions/repository_conditions.py @@ -81,9 +81,15 @@ def page_repository_conditions(rid): return json_error("You are not authorized."), 403 if request.method == "GET": - return json_success([u.condition.to_json() for u in repository.conditions]) + try: + return json_success([u.to_json() for u in repository.conditions]) + except Exception as e: + return json_error("Unknown error:" + str(e)), 400 if request.method == "POST": + if request.json is None: + return json_error("Missing json content."), 400 + if (type_ := request.json.get("type")) is None: return json_error("Missing `type` parameter."), 400 @@ -91,6 +97,8 @@ def page_repository_conditions(rid): type_ = ConditionType(type_) except KeyError: return json_error("Unknown `type` specified."), 400 + except Exception as e: + return json_error("Unknown error: " + str(e)), 400 if not (content := request.json.get("content")): return json_error("Missing `content` parameter."), 400