github.com/cookieai-jar/moby@v17.12.1-ce-rc2+incompatible/api/errdefs/is.go (about) 1 package errdefs 2 3 type causer interface { 4 Cause() error 5 } 6 7 func getImplementer(err error) error { 8 switch e := err.(type) { 9 case 10 ErrNotFound, 11 ErrInvalidParameter, 12 ErrConflict, 13 ErrUnauthorized, 14 ErrUnavailable, 15 ErrForbidden, 16 ErrSystem, 17 ErrNotModified, 18 ErrNotImplemented, 19 ErrUnknown: 20 return e 21 case causer: 22 return getImplementer(e.Cause()) 23 default: 24 return err 25 } 26 } 27 28 // IsNotFound returns if the passed in error is an ErrNotFound 29 func IsNotFound(err error) bool { 30 _, ok := getImplementer(err).(ErrNotFound) 31 return ok 32 } 33 34 // IsInvalidParameter returns if the passed in error is an ErrInvalidParameter 35 func IsInvalidParameter(err error) bool { 36 _, ok := getImplementer(err).(ErrInvalidParameter) 37 return ok 38 } 39 40 // IsConflict returns if the passed in error is an ErrConflict 41 func IsConflict(err error) bool { 42 _, ok := getImplementer(err).(ErrConflict) 43 return ok 44 } 45 46 // IsUnauthorized returns if the the passed in error is an ErrUnauthorized 47 func IsUnauthorized(err error) bool { 48 _, ok := getImplementer(err).(ErrUnauthorized) 49 return ok 50 } 51 52 // IsUnavailable returns if the passed in error is an ErrUnavailable 53 func IsUnavailable(err error) bool { 54 _, ok := getImplementer(err).(ErrUnavailable) 55 return ok 56 } 57 58 // IsForbidden returns if the passed in error is an ErrForbidden 59 func IsForbidden(err error) bool { 60 _, ok := getImplementer(err).(ErrForbidden) 61 return ok 62 } 63 64 // IsSystem returns if the passed in error is an ErrSystem 65 func IsSystem(err error) bool { 66 _, ok := getImplementer(err).(ErrSystem) 67 return ok 68 } 69 70 // IsNotModified returns if the passed in error is a NotModified error 71 func IsNotModified(err error) bool { 72 _, ok := getImplementer(err).(ErrNotModified) 73 return ok 74 } 75 76 // IsNotImplemented returns if the passed in error is an ErrNotImplemented 77 func IsNotImplemented(err error) bool { 78 _, ok := getImplementer(err).(ErrNotImplemented) 79 return ok 80 } 81 82 // IsUnknown returns if the passed in error is an ErrUnknown 83 func IsUnknown(err error) bool { 84 _, ok := getImplementer(err).(ErrUnknown) 85 return ok 86 }