-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
59 lines (49 loc) · 1.36 KB
/
errors.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package docshelf
// ErrNotFound is a special error type for signaling that a requested entity
// doesn't exist.
type ErrNotFound struct {
msg string
}
// ErrRemoved is a special error type for signaling that a requested entity
// has been removed.
type ErrRemoved struct {
msg string
}
// NewErrNotFound returns a new ErrNotFound as a normal error containing
// the given message.
func NewErrNotFound(msg string) error {
return ErrNotFound{msg}
}
// NewErrRemoved returns a new ErrRemoved as a normal error containing the given
// message.
func NewErrRemoved(msg string) error {
return ErrRemoved{msg}
}
// Error implements the Error interface for ErrNotFound. Default messaging is
// used if not supplied.
func (e ErrNotFound) Error() string {
if e.msg == "" {
return "entity does not exist"
}
return e.msg
}
// Error implements the Error interface for ErrRemoved. Default messaging is
// used if not supplied.
func (e ErrRemoved) Error() string {
if e.msg == "" {
return "entity is removed"
}
return e.msg
}
// CheckNotFound is a helper function for determining if an error type is
// actually an ErrNotFound.
func CheckNotFound(err error) bool {
_, ok := err.(ErrNotFound)
return ok
}
// CheckRemoved is a helper function for determining if an error type is
// actually an ErrRemoved.
func CheckRemoved(err error) bool {
_, ok := err.(ErrRemoved)
return ok
}