From a45408ff670ec63240c4d020541b3f87b183f7a4 Mon Sep 17 00:00:00 2001 From: ItsT0ng Date: Sat, 28 Feb 2026 23:06:23 +1100 Subject: [PATCH] fix(providers): replace HTTP-specific regex with standalone status code matcher The precompiled HTTP regex used uppercase "HTTP" which never matched because ClassifyError lowercases the input. Replace it with a case-insensitive word-boundary pattern that matches any standalone 3-digit status code (300-599), which also subsumes the HTTP/x.x case. Add test case for standalone status code extraction. --- pkg/providers/error_classifier.go | 4 ++-- pkg/providers/error_classifier_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/providers/error_classifier.go b/pkg/providers/error_classifier.go index 89842f339..3b13a7f04 100644 --- a/pkg/providers/error_classifier.go +++ b/pkg/providers/error_classifier.go @@ -9,7 +9,7 @@ import ( // Common patterns in Go HTTP error messages var httpStatusPatterns = []*regexp.Regexp{ regexp.MustCompile(`status[:\s]+(\d{3})`), - regexp.MustCompile(`HTTP[/\s]+\d*\.?\d*\s+(\d{3})`), + regexp.MustCompile(`\b([3-5]\d{2})\b`), } // errorPattern defines a single pattern (string or regex) for error classification. @@ -204,7 +204,7 @@ func classifyByMessage(msg string) FailoverReason { } // extractHTTPStatus extracts an HTTP status code from an error message. -// Looks for patterns like "status: 429", "status 429", "HTTP 429", or standalone "429". +// Looks for patterns like "status: 429", "status 429", "HTTP/1.1 429", "HTTP 429", or standalone "429". func extractHTTPStatus(msg string) int { for _, p := range httpStatusPatterns { if m := p.FindStringSubmatch(msg); len(m) > 1 { diff --git a/pkg/providers/error_classifier_test.go b/pkg/providers/error_classifier_test.go index 865aea57a..82db7d31d 100644 --- a/pkg/providers/error_classifier_test.go +++ b/pkg/providers/error_classifier_test.go @@ -306,6 +306,7 @@ func TestExtractHTTPStatus(t *testing.T) { {"status: 429 rate limited", 429}, {"status 401 unauthorized", 401}, {"HTTP/1.1 502 Bad Gateway", 502}, + {"error 429", 429}, {"no status code here", 0}, {"random number 12345", 0}, }