forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 69
/
codes.go
57 lines (52 loc) · 1.39 KB
/
codes.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
package twilio
import (
"encoding/json"
"strconv"
)
// A Twilio error code. A full list can be found here:
// https://www.twilio.com/docs/api/errors/reference
type Code int
func (c *Code) convCode(i *int, err error) error {
if err != nil {
return err
}
if *i == 4107 {
// Twilio incorrectly sent back 14107 as 4107 in some cases. Not sure
// how often this happened or if the problem is more general
*i = 14107
}
*c = Code(*i)
return nil
}
func (c *Code) UnmarshalJSON(b []byte) error {
s := new(string)
if err := json.Unmarshal(b, s); err == nil {
if *s == "" || *s == "null" {
*c = Code(0)
return nil
}
i, err := strconv.Atoi(*s)
return c.convCode(&i, err)
}
i := new(int)
err := json.Unmarshal(b, i)
return c.convCode(i, err)
}
const CodeHTTPRetrievalFailure = 11200
const CodeHTTPConnectionFailure = 11205
const CodeHTTPProtocolViolation = 11206
const CodeReplyLimitExceeded = 14107
const CodeDocumentParseFailure = 12100
const CodeForbiddenPhoneNumber = 13225
const CodeNoInternationalAuthorization = 13227
const CodeSayInvalidText = 13520
const CodeQueueOverflow = 30001
const CodeAccountSuspended = 30002
const CodeUnreachable = 30003
const CodeMessageBlocked = 30004
const CodeUnknownDestination = 30005
const CodeLandline = 30006
const CodeCarrierViolation = 30007
const CodeUnknownError = 30008
const CodeMissingSegment = 30009
const CodeMessagePriceExceedsMaxPrice = 30010