fix(ops): 修复告警状态验证和错误处理逻辑

- 增强告警事件状态验证,添加合法状态值检查
- 移除重试逻辑中的遗留字段赋值
- 修正仓库不可用时的错误类型
- 格式化测试文件代码
This commit is contained in:
IanShaw027
2026-01-14 09:39:18 +08:00
parent 1e169685f4
commit 33f58d583d
11 changed files with 62 additions and 42 deletions

View File

@@ -544,8 +544,14 @@ func (h *OpsHandler) ListAlertEvents(c *gin.Context) {
}
}
// Cursor pagination
if rawTS := strings.TrimSpace(c.Query("before_fired_at")); rawTS != "" {
// Cursor pagination: both params must be provided together.
rawTS := strings.TrimSpace(c.Query("before_fired_at"))
rawID := strings.TrimSpace(c.Query("before_id"))
if (rawTS == "") != (rawID == "") {
response.BadRequest(c, "before_fired_at and before_id must be provided together")
return
}
if rawTS != "" {
ts, err := time.Parse(time.RFC3339Nano, rawTS)
if err != nil {
if t2, err2 := time.Parse(time.RFC3339, rawTS); err2 == nil {
@@ -557,7 +563,7 @@ func (h *OpsHandler) ListAlertEvents(c *gin.Context) {
}
filter.BeforeFiredAt = &ts
}
if rawID := strings.TrimSpace(c.Query("before_id")); rawID != "" {
if rawID != "" {
id, err := strconv.ParseInt(rawID, 10, 64)
if err != nil || id <= 0 {
response.BadRequest(c, "Invalid before_id")