forked from zitadel/zitadel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
already_exists.go
44 lines (34 loc) · 921 Bytes
/
already_exists.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
package errors
import "fmt"
var (
_ AlreadyExists = (*AlreadyExistsError)(nil)
_ Error = (*AlreadyExistsError)(nil)
)
type AlreadyExists interface {
error
IsAlreadyExists()
}
type AlreadyExistsError struct {
*CaosError
}
func ThrowAlreadyExists(parent error, id, message string) error {
return &AlreadyExistsError{CreateCaosError(parent, id, message)}
}
func ThrowAlreadyExistsf(parent error, id, format string, a ...interface{}) error {
return &AlreadyExistsError{CreateCaosError(parent, id, fmt.Sprintf(format, a...))}
}
func (err *AlreadyExistsError) IsAlreadyExists() {}
func (err *AlreadyExistsError) Is(target error) bool {
t, ok := target.(*AlreadyExistsError)
if !ok {
return false
}
return err.CaosError.Is(t.CaosError)
}
func IsErrorAlreadyExists(err error) bool {
_, ok := err.(AlreadyExists)
return ok
}
func (err *AlreadyExistsError) Unwrap() error {
return err.CaosError
}