Check if the price is a positive number.

This commit is contained in:
Liujian committed 2025-12-07 14:03:32 +08:00
1 parent 73cd1a01a0
commit eace543d74
2 files changed
+16

No files matched your search

@@ -58,6 +58,19 @@ def update_mcp_service_info(request: Request, body: dict = Body(...), mcp_manage
# Validate ID is required
if not body.get("id"):
return ResponseUtils.error(error_msg=error_msg.MISSING_PARAMETER)
# Validate price is a positive number if charge_type is per_token
if body.get("charge_type") == ChargeType.PER_CALL:
price = body.get("price")
if price is None or price < 0:
return ResponseUtils.error(error_msg=error_msg.INVALID_PRICE)
if body.get("charge_type") == ChargeType.PER_TOKEN:
input_token = body.get("input_token")
output_token = body.get("output_token")
if input_token is None or input_token < 0:
return ResponseUtils.error(error_msg=error_msg.INVALID_INPUT_TOKEN)
if output_token is None or output_token < 0:
return ResponseUtils.error(error_msg=error_msg.INVALID_OUTPUT_TOKEN)
try:
mcp_manager_service.update(body)
+3
View File
@@ -4,6 +4,9 @@
# 4xx Client Errors
INVALID_REQUEST = {"code": 400, "message": "Invalid request parameters"}
MISSING_PARAMETER = {"code": 400, "message": "Required parameter is missing"}
INVALID_PRICE = {"code": 400, "message": "Price must be a non-negative number"}
INVALID_INPUT_TOKEN = {"code": 400, "message": "Input token must be a non-negative number"}
INVALID_OUTPUT_TOKEN = {"code": 400, "message": "Output token must be a non-negative number"}
INVALID_URL = {"code": 400, "message": "Invalid URL provided"}
INVALID_FORMAT = {"code": 400, "message": "Invalid data format"}