-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
38 lines (29 loc) · 792 Bytes
/
error.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
package ldap
type Error struct {
Type ErrType
Err error
}
func (e *Error) Error() string {
if e.Err != nil {
return e.Err.Error()
}
return e.Type.String()
}
func isError(err error, typ ErrType) bool {
if v, _ := err.(*Error); v != nil {
return v.Type == typ
}
return false
}
//go:generate stringer -type ErrType -trimprefix Err -output error_string.go
type ErrType int
const (
ErrRequestFail ErrType = iota
ErrAuthFail
ErrObjectNotExist
ErrAccountNotExist
)
func IsRequestFail(err error) bool { return isError(err, ErrRequestFail) }
func IsAuthFail(err error) bool { return isError(err, ErrAuthFail) }
func IsObjectNotExist(err error) bool { return isError(err, ErrObjectNotExist) }
func IsAccountNotExist(err error) bool { return isError(err, ErrAccountNotExist) }