upstreamErrorClass returns a short human label for an upstream error — "timeout", "eof", "unreachable", or "other" — suitable for structured logging. It shares the same classification logic as classifyUpstreamError but exposes only the error-class dimension (not HTTP status / reason).
(err error)
| 89 | // logging. It shares the same classification logic as classifyUpstreamError |
| 90 | // but exposes only the error-class dimension (not HTTP status / reason). |
| 91 | func upstreamErrorClass(err error) string { |
| 92 | if err == nil { |
| 93 | return "other" |
| 94 | } |
| 95 | if errors.Is(err, context.DeadlineExceeded) { |
| 96 | return "timeout" |
| 97 | } |
| 98 | var netErr net.Error |
| 99 | if errors.As(err, &netErr) && netErr.Timeout() { |
| 100 | return "timeout" |
| 101 | } |
| 102 | if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) { |
| 103 | return "eof" |
| 104 | } |
| 105 | msg := strings.ToLower(err.Error()) |
| 106 | if strings.Contains(msg, "connection refused") || |
| 107 | strings.Contains(msg, "connection reset") || |
| 108 | strings.Contains(msg, "no route to host") || |
| 109 | strings.Contains(msg, "broken pipe") { |
| 110 | return "unreachable" |
| 111 | } |
| 112 | return "other" |
| 113 | } |
| 114 | |
| 115 | // upstreamRequestURL extracts a best-effort URL string from a raw HTTP |
| 116 | // request buffer. Falls back to the dest-socket address if the request |
no test coverage detected