MCPcopy
hub / github.com/grafana/dskit / getCasErrorCode

Function getCasErrorCode

kv/metrics.go:27–42  ·  view source on GitHub ↗

getCasErrorCode converts the provided CAS error into the code that should be used to track the operation in metrics.

(err error)

Source from the content-addressed store, hash-verified

25// getCasErrorCode converts the provided CAS error into the code that should be used to track the operation
26// in metrics.
27func getCasErrorCode(err error) string {
28 if err == nil {
29 return "200"
30 }
31 if resp, ok := httpgrpc.HTTPResponseFromError(err); ok {
32 return strconv.Itoa(int(resp.GetCode()))
33 }
34
35 // If the error has been returned to abort the CAS operation, then we shouldn't
36 // consider it an error when tracking metrics.
37 if casErr, ok := err.(interface{ IsOperationAborted() bool }); ok && casErr.IsOperationAborted() {
38 return "200"
39 }
40
41 return "500"
42}
43
44type metrics struct {
45 c Client

Callers

nothing calls this directly

Calls 2

HTTPResponseFromErrorFunction · 0.92
GetCodeMethod · 0.45

Tested by

no test coverage detected