github.com/LINBIT/golinstor@v0.52.0/client/apicallerror.go (about) 1 package client 2 3 import ( 4 "strings" 5 ) 6 7 type ApiCallError []ApiCallRc 8 9 func (e ApiCallError) Error() string { 10 var finalErr string 11 for i, r := range e { 12 finalErr += strings.TrimSpace(r.String()) 13 if i < len(e)-1 { 14 finalErr += " next error: " 15 } 16 } 17 return finalErr 18 } 19 20 // Is is a shorthand for checking all ApiCallRcs of an ApiCallError against 21 // a given mask. 22 func (e ApiCallError) Is(mask uint64) bool { 23 for _, r := range e { 24 if r.Is(mask) { 25 return true 26 } 27 } 28 29 return false 30 } 31 32 // Is can be used to check the return code against a given mask. Since LINSTOR 33 // return codes are designed to be machine readable, this can be used to check 34 // for a very specific type of error. 35 // Refer to package apiconsts.go in package linstor for a list of possible 36 // mask values. 37 func (r ApiCallRc) Is(mask uint64) bool { return (uint64(r.RetCode) & mask) == mask } 38 39 // IsApiCallError checks if an error is a specific type of LINSTOR error. 40 func IsApiCallError(err error, mask uint64) bool { 41 e, ok := err.(ApiCallError) 42 if !ok { 43 return false 44 } 45 46 return e.Is(mask) 47 }