-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
40 lines (34 loc) · 1.05 KB
/
errors.go
File metadata and controls
40 lines (34 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package prometheus
import (
"net/http"
)
// ErrorType classifies HTTP errors for better observability
type ErrorType string
const (
ErrorTypeClientError ErrorType = "client_error" // 4xx errors
ErrorTypeServerError ErrorType = "server_error" // 5xx errors
ErrorTypeTimeout ErrorType = "timeout" // 408, 504
ErrorTypeNoWorkers ErrorType = "no_workers" // Worker pool exhausted
)
// classifyError determines the error type based on status code and headers
func classifyError(statusCode int, headers http.Header) ErrorType {
// Check for no workers condition first
if headers.Get(noWorkers) == trueStr {
return ErrorTypeNoWorkers
}
// Classify by status code
switch {
case statusCode == 408 || statusCode == 504:
return ErrorTypeTimeout
case statusCode >= 400 && statusCode < 500:
return ErrorTypeClientError
case statusCode >= 500:
return ErrorTypeServerError
default:
return ErrorTypeServerError
}
}
// isErrorStatus checks if a status code represents an error
func isErrorStatus(statusCode int) bool {
return statusCode >= 400
}