-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
60 lines (47 loc) · 1.08 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
56
57
58
59
60
package rabbitevents
import (
"errors"
"github.com/streadway/amqp"
)
type EventProcessingError struct {
err error
}
var ErrNilContext = errors.New("received nil context")
func NewEventProcessingError(err error) error {
return &EventProcessingError{err}
}
func (e *EventProcessingError) Error() string {
return e.err.Error()
}
func (e *EventProcessingError) Temporary() bool {
return true
}
func IsTemporaryError(err error) bool {
//If the eror was created by status.Errorf, then use that code.
if err, ok := err.(interface {
Temporary() bool
}); ok {
return err.Temporary()
}
nestedErr := errors.Unwrap(err)
if nestedErr != nil {
return IsTemporaryError(nestedErr)
}
return false
}
type MessageError struct {
err error
message amqp.Delivery
}
func NewMessageError(message amqp.Delivery, err error) *MessageError {
return &MessageError{err: err, message: message}
}
func (me *MessageError) Error() string {
return me.err.Error()
}
func (me *MessageError) Unwrap() error {
return me.err
}
func (me *MessageError) GetMessage() amqp.Delivery {
return me.message
}