-
Notifications
You must be signed in to change notification settings - Fork 0
/
unavailable.go
47 lines (37 loc) · 1.28 KB
/
unavailable.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
package zerrors
import (
"errors"
"fmt"
"github.com/samber/oops"
)
const ErrUnavailable = "unavailable"
func ThrowUnavailable(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return oops.Code(ErrUnavailable).Wrap(errors.New(message))
}
func ThrowUnavailabler(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return oops.Code(ErrUnavailable).Wrap(errors.New(message))
}
func Unavailable(message string, KVs ...interface{}) error {
return oops.Code(ErrUnavailable).With(KVs...).Wrap(errors.New(message))
}
func Unavailablef(format string, a ...interface{}) error {
return oops.Code(ErrUnavailable).Wrap(fmt.Errorf(format, a...))
}
func UnavailableBuilder() oops.OopsErrorBuilder {
return oops.Code(ErrUnavailable)
}
func ToUnavailable(parent error, KVs ...interface{}) error {
return oops.Code(ErrUnavailable).With(KVs...).Wrap(parent)
}
func ToUnavailablef(parent error, format string, a ...interface{}) error {
return oops.Code(ErrUnavailable).Wrapf(parent, format, a...)
}
func IsUnavailable(err error) bool {
var possibleError oops.OopsError
if errors.As(err, &possibleError) {
return possibleError.Code() == ErrUnavailable
}
return false
}