-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors.go
51 lines (41 loc) · 1.15 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
package cloudns
import (
"fmt"
"strings"
)
// Constant errors which can be returned by cloudns-go when something goes wrong
const (
ErrHTTPRequest = constError("http request failed")
ErrAPIInvocation = constError("api invocation failed")
ErrIllegalArgument = constError("illegal argument provided")
ErrInvalidOptions = constError("invalid options provided")
ErrMultipleCredentials = constError("more than one kind of credentials specified")
)
type constError string
func (err constError) wrap(inner error) error {
return wrapError{outer: err, inner: inner}
}
func (err constError) Error() string {
return string(err)
}
func (err constError) Is(target error) bool {
errMsg := string(err)
targetMsg := target.Error()
return targetMsg == errMsg || strings.HasPrefix(targetMsg, errMsg+": ")
}
type wrapError struct {
outer constError
inner error
}
func (err wrapError) Error() string {
if err.inner != nil {
return fmt.Sprintf("%s: %v", err.outer.Error(), err.inner)
}
return err.outer.Error()
}
func (err wrapError) Is(target error) bool {
return err.outer.Is(target)
}
func (err wrapError) Unwrap() error {
return err.inner
}