fix(providers): restore http regex and add standalone status code matcher
Restore the http-prefixed regex (without unnecessary (?i) flag since input is already lowercased by ClassifyError) as a mid-priority pattern to reduce false positives. Add a standalone word-boundary matcher as a fallback for bare status codes like "429". Fix test to use lowercased input matching the actual calling convention.
This commit is contained in:
parent
a45408ff67
commit
c3edb3d1d3
2 changed files with 3 additions and 2 deletions
|
|
@ -9,6 +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`),
|
||||
}
|
||||
|
||||
|
|
@ -204,7 +205,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/1.1 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 {
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ func TestExtractHTTPStatus(t *testing.T) {
|
|||
}{
|
||||
{"status: 429 rate limited", 429},
|
||||
{"status 401 unauthorized", 401},
|
||||
{"HTTP/1.1 502 Bad Gateway", 502},
|
||||
{"http/1.1 502 bad gateway", 502},
|
||||
{"error 429", 429},
|
||||
{"no status code here", 0},
|
||||
{"random number 12345", 0},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue