/
errors.go
55 lines (43 loc) · 1.37 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
package controller
import (
"fmt"
"github.com/pkg/errors"
)
// NotFoundError indicates situation when given resource was not found
type NotFoundError struct {
msg string
}
func (e NotFoundError) Error() string { return fmt.Sprintf("not found error: %s", e.msg) }
// NotFound returns information if such error should be treated as not found
func (NotFoundError) NotFound() bool { return true }
// NewNotFoundError returns a new not found error with given message
func NewNotFoundError(format string, args ...interface{}) NotFoundError {
return NotFoundError{msg: fmt.Sprintf(format, args...)}
}
// IsNotFoundError checks if given error is NotFound error
func IsNotFoundError(err error) bool {
err = errors.Cause(err)
nfe, ok := err.(interface {
NotFound() bool
})
return ok && nfe.NotFound()
}
// ConflictError indicates situation when conflict occurs
type ConflictError struct {
ConflictingResource string
}
func (e *ConflictError) Error() string {
return fmt.Sprintf("Conflict Error for [%s]", e.ConflictingResource)
}
type processBindingUsageError struct {
Reason, Message string
}
func (s *processBindingUsageError) Error() string {
return fmt.Sprintf("Reason: %s, details: %s", s.Reason, s.Message)
}
func newProcessServiceBindingError(reason string, err error) *processBindingUsageError {
return &processBindingUsageError{
Reason: reason,
Message: err.Error(),
}
}