MCPcopy
hub / github.com/lxc/incus / StatusErrorMatch

Function StatusErrorMatch

shared/api/error.go:48–64  ·  view source on GitHub ↗

StatusErrorMatch checks if err was caused by StatusError. Can optionally also check whether the StatusError's status code matches one of the supplied status codes in matchStatus. Returns the matched StatusError status code and true if match criteria are met, otherwise false.

(err error, matchStatusCodes ...int)

Source from the content-addressed store, hash-verified

46// status code matches one of the supplied status codes in matchStatus.
47// Returns the matched StatusError status code and true if match criteria are met, otherwise false.
48func StatusErrorMatch(err error, matchStatusCodes ...int) (int, bool) {
49 var statusErr StatusError
50
51 if errors.As(err, &statusErr) {
52 statusCode := statusErr.Status()
53
54 if len(matchStatusCodes) <= 0 {
55 return statusCode, true
56 }
57
58 if slices.Contains(matchStatusCodes, statusCode) {
59 return statusCode, true
60 }
61 }
62
63 return -1, false
64}
65
66// StatusErrorCheck returns whether or not err was caused by a StatusError and if it matches one of the
67// optional status codes.

Callers 5

SmartErrorFunction · 0.92
DevIncusErrorResponseFunction · 0.92
storagePoolVolumePostFunction · 0.92
smartResponseFunction · 0.92
StatusErrorCheckFunction · 0.85

Calls 2

StatusMethod · 0.95
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…