fix(ops): use normalized error type for all classification functions
- Compute normalizedType once and pass to classifyOpsPhase, classifyOpsSeverity, classifyOpsIsBusinessLimited, classifyOpsIsRetryable instead of raw parsed.ErrorType - Add test case verifying known type takes precedence over conflicting code Addresses Copilot review feedback on PR #680.
This commit is contained in:
@@ -662,8 +662,10 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc {
|
|||||||
requestID = c.Writer.Header().Get("x-request-id")
|
requestID = c.Writer.Header().Get("x-request-id")
|
||||||
}
|
}
|
||||||
|
|
||||||
phase := classifyOpsPhase(parsed.ErrorType, parsed.Message, parsed.Code)
|
normalizedType := normalizeOpsErrorType(parsed.ErrorType, parsed.Code)
|
||||||
isBusinessLimited := classifyOpsIsBusinessLimited(parsed.ErrorType, phase, parsed.Code, status, parsed.Message)
|
|
||||||
|
phase := classifyOpsPhase(normalizedType, parsed.Message, parsed.Code)
|
||||||
|
isBusinessLimited := classifyOpsIsBusinessLimited(normalizedType, phase, parsed.Code, status, parsed.Message)
|
||||||
|
|
||||||
errorOwner := classifyOpsErrorOwner(phase, parsed.Message)
|
errorOwner := classifyOpsErrorOwner(phase, parsed.Message)
|
||||||
errorSource := classifyOpsErrorSource(phase, parsed.Message)
|
errorSource := classifyOpsErrorSource(phase, parsed.Message)
|
||||||
@@ -685,8 +687,8 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc {
|
|||||||
UserAgent: c.GetHeader("User-Agent"),
|
UserAgent: c.GetHeader("User-Agent"),
|
||||||
|
|
||||||
ErrorPhase: phase,
|
ErrorPhase: phase,
|
||||||
ErrorType: normalizeOpsErrorType(parsed.ErrorType, parsed.Code),
|
ErrorType: normalizedType,
|
||||||
Severity: classifyOpsSeverity(parsed.ErrorType, status),
|
Severity: classifyOpsSeverity(normalizedType, status),
|
||||||
StatusCode: status,
|
StatusCode: status,
|
||||||
IsBusinessLimited: isBusinessLimited,
|
IsBusinessLimited: isBusinessLimited,
|
||||||
IsCountTokens: isCountTokensRequest(c),
|
IsCountTokens: isCountTokensRequest(c),
|
||||||
@@ -698,7 +700,7 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc {
|
|||||||
ErrorSource: errorSource,
|
ErrorSource: errorSource,
|
||||||
ErrorOwner: errorOwner,
|
ErrorOwner: errorOwner,
|
||||||
|
|
||||||
IsRetryable: classifyOpsIsRetryable(parsed.ErrorType, status),
|
IsRetryable: classifyOpsIsRetryable(normalizedType, status),
|
||||||
RetryCount: 0,
|
RetryCount: 0,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,6 +263,9 @@ func TestNormalizeOpsErrorType(t *testing.T) {
|
|||||||
{"empty type with balance code", "", "INSUFFICIENT_BALANCE", "billing_error"},
|
{"empty type with balance code", "", "INSUFFICIENT_BALANCE", "billing_error"},
|
||||||
{"empty type with subscription code", "", "SUBSCRIPTION_NOT_FOUND", "subscription_error"},
|
{"empty type with subscription code", "", "SUBSCRIPTION_NOT_FOUND", "subscription_error"},
|
||||||
{"empty type no code", "", "", "api_error"},
|
{"empty type no code", "", "", "api_error"},
|
||||||
|
|
||||||
|
// Known type overrides conflicting code-based mapping.
|
||||||
|
{"known type overrides conflicting code", "rate_limit_error", "INSUFFICIENT_BALANCE", "rate_limit_error"},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user