-
Notifications
You must be signed in to change notification settings - Fork 796
/
errors.go
47 lines (40 loc) · 1009 Bytes
/
errors.go
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
41
42
43
44
45
46
47
package ingester
import (
"fmt"
"net/http"
"github.com/prometheus/prometheus/model/labels"
)
type validationError struct {
err error // underlying error
errorType string
code int
labels labels.Labels
}
func makeLimitError(errorType string, err error) error {
return &validationError{
errorType: errorType,
err: err,
code: http.StatusBadRequest,
}
}
func makeMetricLimitError(errorType string, labels labels.Labels, err error) error {
return &validationError{
errorType: errorType,
err: err,
code: http.StatusBadRequest,
labels: labels,
}
}
func (e *validationError) Error() string {
if e.err == nil {
return e.errorType
}
if e.labels == nil {
return e.err.Error()
}
return fmt.Sprintf("%s for series %s", e.err.Error(), e.labels.String())
}
// wrapWithUser prepends the user to the error. It does not retain a reference to err.
func wrapWithUser(err error, userID string) error {
return fmt.Errorf("user=%s: %s", userID, err)
}