forked from keys-pub/keys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
42 lines (34 loc) · 801 Bytes
/
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
package keys
import (
"fmt"
"github.com/pkg/errors"
)
// ErrVerifyFailed if key verify failed.
var ErrVerifyFailed = errors.New("verify failed")
// ErrNotFound describes a key not found error when a key is required.
type ErrNotFound struct {
ID string
}
// NewErrNotFound constructs a ErrNotFound.
func NewErrNotFound(id string) error {
return ErrNotFound{ID: id}
}
func (e ErrNotFound) Error() string {
if e.ID == "" {
return "not found"
}
return fmt.Sprintf("%s not found", e.ID)
}
type tempError interface {
Temporary() bool
}
// IsTemporaryError returns true if the error has Temporary() function and that returns true
func IsTemporaryError(err error) bool {
switch err := errors.Cause(err).(type) {
case tempError:
if err.Temporary() {
return true
}
}
return false
}