v0.5.4: fix 500 на массив + валидация serviceId (int>0)
This commit is contained in:
@@ -80,7 +80,7 @@ SERVICES = _DF["SERVICES"]
|
||||
OPS_INDEX = _DF["OPS_INDEX"]
|
||||
|
||||
DELAY = float(os.getenv("MOCK_OP_DELAY", "0.1"))
|
||||
VERSION = "0.5.3"
|
||||
VERSION = "0.5.4"
|
||||
|
||||
|
||||
def get_services(stand_id):
|
||||
|
||||
@@ -72,6 +72,11 @@ def create_instance():
|
||||
на случай если заголовок не дойдёт.
|
||||
"""
|
||||
body = request.get_json(silent=True) or {}
|
||||
|
||||
# ⛔ body должен быть dict, не массив и не примитив
|
||||
if not isinstance(body, dict):
|
||||
return jsonify({"error": "request body must be a JSON object"}), 400
|
||||
|
||||
service_id = body.get("serviceId")
|
||||
display_name = body.get("displayName", "unnamed")
|
||||
|
||||
@@ -79,6 +84,10 @@ def create_instance():
|
||||
if service_id is None:
|
||||
return jsonify({"error": "serviceId is required"}), 400
|
||||
|
||||
# Валидация: serviceId должен быть целым положительным числом
|
||||
if not isinstance(service_id, int) or isinstance(service_id, bool) or service_id <= 0:
|
||||
return jsonify({"error": "serviceId must be a positive integer"}), 400
|
||||
|
||||
# Проверка что сервис существует в конфиге
|
||||
svc_def = SERVICES.get(service_id)
|
||||
if not svc_def:
|
||||
|
||||
Reference in New Issue
Block a user