forked from xiaojiaoyu100/aliyun-mns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
125 lines (104 loc) · 3.72 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package alimns
import (
"encoding/xml"
"github.com/xiaojiaoyu100/cast"
)
// MnsError 错误码
type MnsError string
func (e MnsError) Error() string {
return string(e)
}
// customize code
const (
unknownError = MnsError("Unknown")
visibilityTimeoutError = MnsError("VisibilityTimeoutOutOfRange")
createQueueNoContentError = MnsError("CreateQueueNoContent")
createQueueConflictError = MnsError("CreateQueueConflict")
messageBodyLimitError = MnsError("MessageBodyLimit")
sendMessageTimeoutError = MnsError("SendMessageTimeout")
messageDelaySecondsOutOfRangeError = MnsError("MessageDelaySecondsOutOfRange")
batchSendMessageTryLimitError = MnsError("BatchSendMessageTryLimit")
batchSendMessageNumLimitError = MnsError("BatchSendMessageNumLimit")
handleCrashError = MnsError("handleCrash")
queueNumExceededLimitError = MnsError("QueueNumExceededLimit")
subscriptionNameLengthError = MnsError("SubscriptionNameLengthError")
subscriptionNameInvalidError = MnsError("SubscriptionNameInvalid")
subscriptionAlreadyExistError = MnsError("SubscriptionAlreadyExist")
endpointInvalidError = MnsError("EndpointInvalid")
invalidArgumentError = MnsError("InvalidArgument")
topicAlreadyExistError = MnsError("TopicAlreadyExist")
topicNameLengthError = MnsError("TopicNameLengthError")
topicNotExistError = MnsError("TopicNotExist")
)
// aliyun mns error code
const (
messageNotExistError = MnsError("MessageNotExist")
queueNotExistError = MnsError("QueueNotExist")
internalError = MnsError("InternalError")
)
// IsUnknown 是否是未知错误
func IsUnknown(err error) bool {
return err == unknownError
}
// IsVisibilityTimeout 是否是可见时间不在范围
func IsVisibilityTimeout(err error) bool {
return err == visibilityTimeoutError
}
// IsCreateQueueNoContent 是否是createQueueNoContentError
func IsCreateQueueNoContent(err error) bool {
return err == createQueueNoContentError
}
// IsCreateQueueConflict 是否是createQueueConflictError
func IsCreateQueueConflict(err error) bool {
return err == createQueueConflictError
}
// IsMessageBodyLimit 是否超出范围
func IsMessageBodyLimit(err error) bool {
return err == messageBodyLimitError
}
// IsSendMessageTimeout 是否发送消息超时
func IsSendMessageTimeout(err error) bool {
return err == sendMessageTimeoutError
}
// IsMessageDelaySecondsOutOfRange 延时时长是否合理
func IsMessageDelaySecondsOutOfRange(err error) bool {
return err == messageDelaySecondsOutOfRangeError
}
// IsHandleCrash 是否是处理函数崩溃错误
func IsHandleCrash(err error) bool {
return err == handleCrashError
}
// IsInternalError 是否内部错误
func IsInternalError(err error) bool {
return err == internalError
}
// RespErr 阿里云回复错误
type RespErr struct {
XMLName xml.Name `xml:"Error"`
XMLNs string `xml:"xmlns,attr"`
Code string `xml:"Code"`
Message string `xml:"Message"`
RequestID string `xml:"RequestId"`
HostID string `xml:"HostId"`
}
func shouldRetry(err error) bool {
return IsInternalError(err) || cast.ShouldRetry(err)
}
type transientError interface {
error
// Transient returns whether the error is transient, if returns true, the handler error will not be reported in a
// short period of time.
Transient() bool
}
// TransientError implements the transientError interface.
type TransientError struct {
Err error
}
// Transient means the error is transient.
func (err TransientError) Transient() bool {
return true
}
// Error implements the error interface.
func (err TransientError) Error() string {
return err.Err.Error()
}