-
Notifications
You must be signed in to change notification settings - Fork 16
/
internal.go
46 lines (35 loc) · 1.2 KB
/
internal.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
package errors
import "strings"
const (
Internal = "IN000"
Config = "IN100"
DependencyFailure = "IN200"
)
// nolint
var ErrNotImplemented = NotImplementedError("this operation is not yet implemented. Please contact your administrator")
var ErrNotSupported = NotSupportedError("this operation is not supported. Please contact your administrator")
func isErrorClass(code, base string) bool {
// Delete tailing 0's of the base error code
for base[len(base)-1] == '0' {
base = base[:len(base)-1]
}
return strings.HasPrefix(code, base)
}
func ConfigError(format string, a ...interface{}) *Error {
return Errorf(Config, format, a...)
}
func IsConfigError(err error) bool {
return isErrorClass(FromError(err).GetCode(), Config)
}
func DependencyFailureError(format string, a ...interface{}) *Error {
return Errorf(DependencyFailure, format, a...)
}
func IsDependencyFailureError(err error) bool {
return isErrorClass(FromError(err).GetCode(), DependencyFailure)
}
func NotImplementedError(format string, a ...interface{}) *Error {
return Errorf(NotImplemented, format, a...)
}
func IsNotImplementedError(err error) bool {
return isErrorClass(FromError(err).GetCode(), NotImplemented)
}