-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors.go
65 lines (52 loc) · 1.54 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
60
61
62
63
64
65
package kosmo
var (
ErrIsAlreadyExists = &KosmoError{}
ErrNotFound = &KosmoError{}
ErrBadRequest = &KosmoError{}
ErrForbidden = &KosmoError{}
ErrUnauthorized = &KosmoError{}
ErrInternalServerError = &KosmoError{}
ErrServiceUnavailable = &KosmoError{}
)
type KosmoError struct {
message string
err error
errorType error
}
func newKosmoError(errorType *KosmoError, message string, err error) *KosmoError {
return &KosmoError{
message: message,
err: err,
errorType: errorType,
}
}
func (e *KosmoError) Error() string {
return e.message
}
func (e *KosmoError) Is(target error) bool {
return e.errorType == target
}
func (e *KosmoError) Unwrap() error {
return e.err
}
func NewNotFoundError(message string, err error) error {
return newKosmoError(ErrNotFound, message, err)
}
func NewIsAlreadyExistsError(message string, err error) error {
return newKosmoError(ErrIsAlreadyExists, message, err)
}
func NewBadRequestError(message string, err error) error {
return newKosmoError(ErrBadRequest, message, err)
}
func NewForbiddenError(message string, err error) error {
return newKosmoError(ErrForbidden, message, err)
}
func NewUnauthorizedError(message string, err error) error {
return newKosmoError(ErrUnauthorized, message, err)
}
func NewInternalServerError(message string, err error) error {
return newKosmoError(ErrInternalServerError, message, err)
}
func NewServiceUnavailableError(message string, err error) error {
return newKosmoError(ErrServiceUnavailable, message, err)
}