From 71bc2e6aab51ebec6387f56e7431ff0d846daf3f Mon Sep 17 00:00:00 2001 From: fawney19 Date: Thu, 25 Dec 2025 22:44:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=98=B2=E6=AD=A2=E9=99=A4=E9=9B=B6=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/health/endpoint.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/services/health/endpoint.py b/src/services/health/endpoint.py index 0e51a69..67885d0 100644 --- a/src/services/health/endpoint.py +++ b/src/services/health/endpoint.py @@ -234,7 +234,14 @@ class EndpointHealthService: for api_format in format_key_mapping.keys() } - # 计算时间范围(使用秒级精度避免整除导致的除零错误) + # 参数校验(API 层已通过 Query(ge=1) 保证,这里做防御性检查) + if lookback_hours <= 0 or segments <= 0: + raise ValueError( + f"lookback_hours and segments must be positive, " + f"got lookback_hours={lookback_hours}, segments={segments}" + ) + + # 计算时间范围 segment_seconds = (lookback_hours * 3600) / segments start_time = now - timedelta(hours=lookback_hours)