-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
47 lines (37 loc) · 1.1 KB
/
error.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 google_pubsub
import "google.golang.org/grpc/codes"
// PubsubError is the struct which implements error
type (
PubsubError struct {
retry bool
innerError error
}
ErrCodeAlias codes.Code
)
// Retriable check if should retry or not
func (p PubsubError) Retriable() bool { return p.retry }
// Retry specify that this erro should be retriable
func (p PubsubError) Retry() PubsubError {
p.retry = true
return p
}
// Error implements Error interface
func (p PubsubError) Error() string { return p.innerError.Error() }
// Is implements interface to enable to compare error with given type
func (p PubsubError) Is(target error) bool {
if _, ok := target.(PubsubError); ok {
return ok
}
return false
}
// NewPubsubError retrieve instance of error type
func NewPubsubError(err error) PubsubError {
return PubsubError{innerError: err, retry: false}
}
func (ec ErrCodeAlias) IsDeadLineOrCanceledError() bool {
return ec == ErrCodeAlias(codes.DeadlineExceeded) ||
ec == ErrCodeAlias(codes.Canceled)
}
func (ec ErrCodeAlias) AlreadyExists() bool {
return ec == ErrCodeAlias(codes.AlreadyExists)
}