-
Notifications
You must be signed in to change notification settings - Fork 1
/
payload_error.go
156 lines (133 loc) · 4.2 KB
/
payload_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package valuefirst
import "fmt"
// ResponseMessage is the message response of SendSMS.
type ResponseMessage struct {
MessageAck ResponseMessageAck `json:"MESSAGEACK"`
}
// GetError returns the error if any.
func (r *ResponseMessage) GetError() (err error) {
err = r.MessageAck.GetError()
return
}
// ResponseMessageAck is the message part of the ResponseMessage.
type ResponseMessageAck struct {
GUID interface{} `json:"GUID"`
// "Err": {
// "Desc": "The Specified message does not conform to DTD",
// "Code": 65535
// }
Error *ResponseMessageAckError `json:"Err,omitempty"`
}
// ResponseMessageAckError is the error part of the ResponseMessageAck.
type ResponseMessageAckError struct {
Description string `json:"Desc"`
Code int `json:"Code"`
}
// Error implements the error interface.
func (r *ResponseMessageAckError) Error() string {
return fmt.Sprintf(
"error message ACK: %s (code: %d)",
r.Description,
r.Code,
)
}
// GetError returns the error if any.
func (r *ResponseMessageAck) GetError() (err error) {
if r.Error != nil {
err = r.Error
return
}
switch newType := r.GUID.(type) {
case *ResponseMessageAckGUID:
err = newType.GetError()
case *ResponseMessageAckGUIDs:
err = newType.GetError()
}
return
}
// ResponseMessageAckGUIDs is a collection of ResponseMessageAckGUID.
type ResponseMessageAckGUIDs []ResponseMessageAckGUID
// GetError returns the error if any.
func (r ResponseMessageAckGUIDs) GetError() (err error) {
var errList = new(ErrorList)
defer func() {
if len(*errList) <= 0 {
return
}
err = *errList
}()
for _, val := range r {
switch newType := val.Error.(type) {
case *ResponseMessageAckGUIDError:
errList.Append(newType)
case *ResponseMessageAckGUIDErrors:
errList.Append(newType)
}
}
return
}
// ResponseMessageAckGUID is the GUID part of the ResponseMessageAck.
type ResponseMessageAckGUID struct {
// A globally unique message ID that is generated for each <SMS> tag.
// Note that, in future to check the status of the message you must save this code.
GUID string `json:"GUID"`
// The date and time when the transaction was completed.
SubmitDate string `json:"SUBMITDATE"`
// (In case of any error)
// To conserve bandwidth utilization ValueFirst JSON API only sends
// Sequence information of messages that has either some error or were rejected
// because of some error. If there are no errors in a particular message,
// you shall not receive any confirmation of each address SEQ.
// For instance, in the above example in message ID 1 (of client)
// the TO number "My company" was rejected as non-numeric.
// The second message does not have any error,
// and hence there was no error information for the second part.
// SEQ: The Sequence ID (provided by client) that has error.
// CODE: Reason why the message wasn’t accepted.
// The table shown next describes these error conditions.
Error interface{} `json:"ERROR,omitempty"`
// Unique SMS ID sent by the customer. For each message a unique GUID is generated.
// The Server sends the SMS ID so that
// the client application can map the GUID to the SMS ID provided by them.
ID int `json:"ID"`
}
// GetError returns the Error of the ResponseMessageAckGUID.
func (r *ResponseMessageAckGUID) GetError() (err error) {
switch newType := r.Error.(type) {
case *ResponseMessageAckGUIDError:
err = newType
case *ResponseMessageAckGUIDErrors:
err = newType
}
return
}
// ResponseMessageAckGUIDErrors is the collection of the ResponseMessageAckGUIDError.
type ResponseMessageAckGUIDErrors []ResponseMessageAckGUIDError
// Error implements the error interface.
func (r ResponseMessageAckGUIDErrors) Error() (res string) {
var errList ErrorList
for _, err := range r {
errList.Append(&err)
}
res = errList.Error()
return
}
// ResponseMessageAckGUIDError is the error part of the ResponseMessageAckGUID.
//
// "ERROR": {
// "CODE": 28675,
// "SEQ": 1
// },
type ResponseMessageAckGUIDError struct {
Code int `json:"CODE"`
Sequence int `json:"SEQ"`
}
// Error implements the error interface.
func (r *ResponseMessageAckGUIDError) Error() (res string) {
res = fmt.Sprintf(
"error ValueFirst: CODE: %d, SEQ: %d",
r.Code,
r.Sequence,
)
return
}